Vijay
Vijay

Reputation: 67291

variable with multiple lines.delete first two lines in perl

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?

Upvotes: 1

Views: 716

Answers (2)

Orabîg
Orabîg

Reputation: 12012

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)

Upvotes: 2

librarian
librarian

Reputation: 129

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)

Upvotes: 0

Related Questions