1

I have a result of an sql query.it returns some 10 rows like below:

if i do the below in my perl script.

print $result

it gives me the output :

 key       value                            
 ----------- ------------------------------ 
  1428116300 0003000                        
   560779655 0003001                        
   173413463 0003002                        
      315642 0003003                        
  1164414857 0003004                        
   429589116 0003005 

i just want to acheive that the first two lines to be deleted. and store the rest of each line in an array. could any body please tell how do i achive this?

Vijay
  • 65,327
  • 90
  • 227
  • 319

2 Answers2

2

With something like :

my @lines = split /\n/, $result;
splice @lines,0,2;

Explanations :

split /\n/, $result is cutting your variable into an array of lines.

grep /^[\s\d]+$/ is filtering this array, and only keeps the elements that are a single line of spaces or digits (thus removing the first two lines)

Vijay
  • 65,327
  • 90
  • 227
  • 319
Orabîg
  • 11,718
  • 6
  • 38
  • 58
  • @Orabig.Thanks .the logic is working.but i want to delete first two lines only.i donot want to use grep here.I will change your answer. – Vijay Sep 21 '12 at 07:34
0

Data-independent, little roundabout way: If you print $result out in a file, you can

use Tie::File;

tie @lines, Tie::File, $file or die "can't update $file: $!";
delete $lines[1];
delete $lines[2];

(untested)

librarian
  • 129
  • 10