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

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.

Replies are listed 'Best First'.
RE: RE: RE: RE: Re: If
by KM (Priest) on Jun 08, 2000 at 22:48 UTC
    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