Jenda - Thank you for you very clear explanation. Dick Fell Jenda Krynicky wrote: > > From: richard noel fell <[EMAIL PROTECTED]> > > > Here is an abridged version of what I am trying to do which is: > > 1) write to a file in one subroutine > > 2) write the contents of the original file to another file in a > > separate subroutine. > > > > However, I get the error message: > > > > Use of uninitialized value in string at ./scratch2.pl line 24, <In1> > > line 1. Use of uninitialized value in string at ./scratch2.pl line 24, > > <In1> line 2. ... > > > > I cannot figure out what is happening. Can anyone explain this > > behavior to me? Thanks, Dick Fell > > > > sub print_out{ > > open In1,"/home/rfell/tutoring/beaven/webproject/tmp/in.tmp" > > or die "Cannot open in.tmp:$!"; > > open Out1, ">/home/rfell/tutoring/beaven/webproject/tmp/out.tmp" > > or die "Cannot open out.tmp:$!"; > > while(defined<In1>){ > > print Out1 "$_"; } > > } > > The problem is in the while() { line. > If you write this : > > while (<In1>) { > > then the lines are read from In1 one by one and stored in $_. > As soon as there is nothing more to read, the loop ends. > > But the automatic assignment to $_ ONLY works if there is nothing > else in the loop condition but the <FILEHANDLE>. So the > > while (defined <In1>) { > > reads a line from In1, tests whether there was a line to read and > throws away the line it read. And $_ is not even touched. > > Jenda > > P.S.: DO NOT USE > print "$_"; > or > print "$variable"; > Do not enclose variable names in quotes unless there is some > more text into which you want to insert the variable value. > > =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== > There is a reason for living. There must be. I've seen it somewhere. > It's just that in the mess on my table ... and in my brain > I can't find it. > --- me
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]