in reply to RE: Re: If
in thread If doesn't work

Why the use of the block to open the file? Why the use of local *FILE here? Why are you making two variables instead of just @foo = <FILE>; $foo[1];? Why not:

print qq[<HTML><frameset cols="100%,290%"> <frame src="commands.cgi?name=$name" name="commands"> <frame src="base.cgi?name=$name" name="game"> </frameset> </HTML>];
? Why not exit at the end of error()? Otherwise the script will continue, which would make no sense, and possibly cause other errors.

Cheers,
KM

Replies are listed 'Best First'.
RE: RE: RE: Re: If
by takshaka (Friar) on Jun 08, 2000 at 22:32 UTC
    Why are you making two variables instead of just @foo = <FILE>; $foo[1];?

    I know the data file probably has only a couple of lines at most, but if it had 1000 why would you want to read in all 1000 when you only want the second? Of course, using two scalars is wasteful. my $line = (<FILE>, <FILE>);

    I suspect the OP really wants the first line--not the second--which would make slurping into an array even more unnecessary.

      Well, if I had a 1000 line file and I always only wanted the second line, I would put the data from the second line elsewhere. But, personally, I think what you have there is quite ugly. I would use something more like the following to get the second line:

      my $line = (map scalar (<FH>),0..1)[1];

      If you use scalar() in there the filehandle will not be used in list context, therefor not being read in all at once.

      Cheers,
      KM