in reply to help with the diamond operator
In this case, the first line you read is not actually used. Instead of your suggestion of while(1), try this:while (<$foo>) # Read in a line to $_ { print <$foo>; # Print the rest of the file }
Or, in a more terse fashion:while (<$foo>) # Read in a line to $_ { print; # Print $_ }
print while (<$foo>); # Read in lines and print themOr, even the approach you seem to have hit on by accident:
print <$foo>; # Print all lines from the fileThose are all simple ways of doing what you are looking for.
The IO::Handle methods may have more appeal for Java people who want everything OO. Others find the traditional method more appealing. Both do the job, so the choice is yours.# -- IO Implementation -------------------------------- use IO::File; my $file = 'foo.txt'; my $handle = new IO::File ($file) || die "Could not open $file\n"; print $handle->getlines(); $handle->close(); # -- Traditional -------------------------------------- my $file = 'foo.txt'; open (FILE, $file) || die "Could not open $file\n"; print <FILE>; close (FILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: help with (Reading A File)
by La12 (Sexton) on Jul 27, 2001 at 08:19 UTC |