in reply to my $x = <expr>; vs my $x; $x = <expr>;
No, they are equivalent as you have written them. I prefer to initialize at the same time I declare lexical, as in your first example. That helps enforce locality of the variable. I generally split them only when $x is set within a smaller scope, but $x is needed in a wider one. An example,
$x is available outside the braces, but the apparatus needed to set it is hidden from the rest of the program.my $x; { open my $fh, '<', '/path/to/foo.file' or die $! $x = <$fh>; close $fh; }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: my $x = <expr>; vs my $x; $x = <expr>;
by Aristotle (Chancellor) on Jun 05, 2004 at 21:32 UTC | |
by Roy Johnson (Monsignor) on Jun 06, 2004 at 03:41 UTC | |
by Aristotle (Chancellor) on Jun 07, 2004 at 15:20 UTC |