FreeKB - Remove first line from an array in Perl
Remove first line from an array in Perl

Home > Search


Let's say you have multple lines of data in an array

my @foo = qw(
line 1
line 2
line 3
);

 

You can print the array.

print @foo;

 

And all of the lines will be printed.

line 1
line 2
line 3

 

Splice can be used to remove the first line from the array.

splice (@foo, 0, 1);

 

Now when you print the array, line 1 has been removed.

line 2
line 3

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments