![]() |
Anyone knows how to make a perl script read 1 line in a file?
Ok
I want to make a script that reads only the first line of a text file. The name of the text file is data.txt Does any of you, programmers, knows how to do it? The script is written in perl. Thanks, Steve |
get the book
visual quickstart guide perl and cgi for the world wide web elizabeth castro makes perl reaaaaaly easy btw you could do the code in php to read one line w/ less code ;) |
Thanks Fly, I'll try to find this book http://bbs.gofuckyourself.net/board/smile.gif
I actually have one called: Perl Visual Pro But there is nothing about what I ask into it http://bbs.gofuckyourself.net/board/frown.gif Thanks again, Steve |
There are lots of ways...here's one off the cuff
my $linecount = 0; open FILE,"<file.txt" || die "Unable to open file: $!"; my @lines = <FILE>; close(FILE); my $line; foreach $line(@lines) { $linecount++; while ($linecount<2) { print "$line"; } } should work in most contexts. |
never mind...the board won't print the code correctly
|
Well, I actually find a way to do it...
Thanks anyway guys http://bbs.gofuckyourself.net/board/smile.gif |
php code:
$stuff = file('filename.txt'); $line = $stuff[0]; |
yeah i can't believe how easy php is ;)
|
All times are GMT -7. The time now is 12:41 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123