in reply to help with the diamond operator

The problem is that you're reading the $foo handle before printing. This has the effect of zapping the first line. Here's how it goes:
while (<$foo>) # Read in a line to $_ { print <$foo>; # Print the rest of the file }
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; # Print $_ }
Or, in a more terse fashion:
print while (<$foo>);  # Read in lines and print them
Or, even the approach you seem to have hit on by accident:
print <$foo>;  # Print all lines from the file
Those are all simple ways of doing what you are looking for.

If you're using a book for this, I'm curious as to the name of it, because that is some pretty bizarre Perl. If, however, this is your own code, then it is good that you are willing to explore. I am just worried that this came from a book which advocates that kind of programming.

What has me mystified in particular is the mixing of IO::Handle methods and the traditional reading techniques. Usually you're using IO::Handle for a reason, but in this case it seems you're just making your life difficult. Here's the program written two ways:
# -- 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);
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.

However, try and keep your approach "pure". In some cases, mixing different types of calls can cause subtle errors, often when two approaches are mostly, but not entirely equivalent.

Replies are listed 'Best First'.
Re: Re: help with (Reading A File)
by La12 (Sexton) on Jul 27, 2001 at 08:19 UTC
    Hi tadman,
    First i'd like to thank everyone for their help. I'm reading Networking with Perl and Professional Perl. I'm writing a server & client and have been using IO::Socket. For the script above I figured i'd stick with same approach and use IO::File (I'm used to using open (FILE, $file)). The reason I wrote
    while (<$foo>){ print <$foo>; }
    is because of the IO:Socket programing
    while (<$connection>); do... }