Re: Going to a specific line in a file. by fenLisesi (Priest) on Jun 13, 2007 at 14:01 UTC |
Unless your lines are of constant length, you have to go line by line. Cheers. | [reply] |
Re: Going to a specific line in a file. by marto (Chancellor) on Jun 13, 2007 at 14:04 UTC |
| [reply] |
Re: Going to a specific line in a file. by citromatik (Curate) on Jun 13, 2007 at 14:05 UTC |
use strict;
use warnings;
use Tie::File;
my $file = shift @ARGV;
tie my @arr, 'Tie::File', $file;
#Update: (thanks Corion and JohnGG)
#print $arr[15]."\n";
print $arr[14]."\n";
citromatik | [reply] [d/l] |
|
print $arr[15]."\n";
<nit>That is the 16th line.</nit>
Also, why not just interpolate into the string rather than using concatenation?
print qq{$arr[14]\n};
Cheers, JohnGG | [reply] [d/l] [select] |
Re: Going to a specific line in a file. by ikegami (Pope) on Jun 13, 2007 at 14:13 UTC |
Tie::File still reads line by line, and has a lot of overhead. Alternative:
do {
die("Premature EOF")
if not defined <FILE>;
} while $. < 14;
my $line15 = <FILE>;
| [reply] [d/l] |
Re: Going to a specific line in a file. by Anonymous Monk on Jun 13, 2007 at 19:38 UTC |
#!/usr/bin/perl
open file,"./testFile.txt" or die;
while (<file>) {
next if (1..6); --> this skips the first 6 lines.
print "$_\n";
}
| [reply] |
Re: Going to a specific line in a file. by Spidy (Chaplain) on Jun 13, 2007 at 23:26 UTC |
This sounds like a homework question to me...
| [reply] |
|
May be for u it may seem like a homework question, bt not for me..it was one doubt i encountered during my coding..
It may be because our wisdom levels are far apart in magnitude..... Hatsoff Mr Spidy....
| [reply] |
|
I think this is a place where we institute ourselves to help each other.... rather than to make fun of others Mr Spidy..
| [reply] |
|
Don't be angry, actually, You've found what you what.
UPDATE
correct stupid mistake according to -b's message.
I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
| [reply] |
Re: Going to a specific line in a file. by ctilmes (Priest) on Jun 14, 2007 at 11:28 UTC |
| [reply] |
Re: Going to a specific line in a file. by Asmo (Monk) on Jun 14, 2007 at 20:56 UTC |
open (DATAFILE, $filename);
@lines = <DATAFILE>;
close(DATAFILE);
print $lines[14];
| [reply] [d/l] |