in reply to Re: Variable declaration optimization?
in thread Variable declaration optimization?

I think this one looks the cleanest:
my( $var1, $var2 ) = ( subroutine0_with_return_value(), subroutine1_with_return_value() );

but I'm lazy and I find that:

my $var1 = sub_w_ret_val1(); my $var2 = sub_w_ret_val2();

is the easiest to think through, especially when assigning several return values.

but I was taught that:

public static void main(){ int var1, var2; //declare more variables here var1 = sub_w_ret_val(); var2 = sub_w_ret_val(); }
(note the language change)

was the correct method for declaring variables.

while I'm not saying I find the third is the best method for declaring and using variables, I sometimes find myself doing the Perl (is it Perl or perl?) equivalent.

my $file1, $file2 my $var1, $var2 $var1 = &sub_w_ret_val(); $var2 = &sub_w_ret_val();

any way, that's my two cents on code writing optimization.

Replies are listed 'Best First'.
Re^3: Variable declaration optimization?
by chromatic (Archbishop) on Oct 13, 2010 at 02:18 UTC

    That third example is the vestigial remnant of ancient compilers and language versions which care more about what the computers of the day used to do than usability.

    (Your final example has prototype behavior you likely did not intend.)