G'day ansh007,
Welcome to the Monastery.
Take a look at "perlop: Range Operators" and the eof function. Your "from line number 100 till end" can be written in Perl as "100 .. eof".
Given this file:
$ cat XXX A B C D E
And an alias I use frequently:
$ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -E'
You can read from line 3 to the end like this:
$ perle 'open my $fh, "<", "XXX"; while (<$fh>) { print if 3 .. eof }' C D E
That also works with a literal line number instead of eof. For example, to print lines at the start, or in the middle:
$ perle 'open my $fh, "<", "XXX"; while (<$fh>) { print if 1 .. 3 }' A B C
$ perle 'open my $fh, "<", "XXX"; while (<$fh>) { print if 2 .. 4 }' B C D
For those last two, once you've read all the wanted lines, you can exit the while loop early with the last function.
See also: open for a better way to open files; the pragma index for links to strict, warnings and autodie (you should always use the first two; I highly recommend the third for simple I/O error checking); and, if you're unfamiliar with the "-M" and "-E" switches I've used, perlrun.
— Ken
In reply to Re: Loading a part of the file to array using Tie::File
by kcott
in thread Loading a part of the file to array using Tie::File
by ansh007
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |