
japhy
Enthusiast
Mar 2, 2001, 1:06 PM
Post #2 of 2
(368 views)
|
Since you just started learning Perl, I suggest you spend a good week or so getting familiar with Perl's handy documentation. It's a time-saver like you've never known. Here is how I would approach your problem:
open FILE, $filename or die "can't read $filename: $!"; while (<FILE>) { print "$. $_"; } close FILE; The $. variable holds the current line number of the file you're reading from. Even if this variable didn't exist, you could use a simple counter:
my $line = 1; open FILE, $filename or die "can't read $filename: $!"; while (<FILE>) { print "$line $_"; $line++; } close FILE; The Perl documentation is available on this site (there's a link on the left), and on your computer (if you have perl). perldoc perl will help you get started. Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author
|