GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Anyone knows how to make a perl script read 1 line in a file? (https://gfy.com/showthread.php?t=40281)

Rod 10-10-2001 08:43 AM

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


TheFLY 10-10-2001 11:33 AM

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 ;)


Rod 10-10-2001 12:10 PM

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

Tuzz 10-10-2001 02:33 PM

There are lots of ways...here's one off the cuff

my $linecount = 0;
open FILE,"<file.txt" &#0124;&#0124; 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.

Tuzz 10-10-2001 02:37 PM

never mind...the board won't print the code correctly

Rod 10-10-2001 03:20 PM

Well, I actually find a way to do it...
Thanks anyway guys http://bbs.gofuckyourself.net/board/smile.gif

Lane 10-10-2001 06:09 PM

php code:

$stuff = file('filename.txt');
$line = $stuff[0];

TheFLY 10-10-2001 06:25 PM

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