in reply to Re: my $x = <expr>; vs my $x; $x = <expr>;
in thread my $x = <expr>; vs my $x; $x = <expr>;

I'd write that as

my $x = do { open my $fh, '<', '/path/to/foo.file' or die $! <$fh>; };

Note that $fh is auto-closed due to falling out of scope.

Update: the last line was not meant to be $x = <$fh> of course.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^3: my $x = <expr>; vs my $x; $x = <expr>;
by Roy Johnson (Monsignor) on Jun 06, 2004 at 03:41 UTC
    You can't use $x in the same statement as you declare it. Your second use of $x is global. The last line in the block should be just scalar <$fh>

    The PerlMonk tr/// Advocate
      That was just a mistake. Thanks for catching it. scalar is not necessary here, btw, because my $x = already provides scalar context.

      Makeshifts last the longest.