swinging_simian has asked for the wisdom of the Perl Monks concerning the following question:
(I added some line spacing in there for readability, so it may need reformatting to get it to run)>perl -we 'use strict; sub test{ my $i = shift; my $params = shift; my $test1 = $params->{test} if exists $params->{test}; print "test1 after hash assignment:\t\t$test1\n"; $test1 = $i if ! defined $test1; print "i = $i\ttest1 after defaulting to i:\t$test1\n";} for my $i(0..3){ &test($i,{});}' Use of uninitialized value $test1 in concatenation (.) or string at -e + line 1. test1 after hash assignment: i = 0 test1 after defaulting to i: 0 test1 after hash assignment: 0 i = 1 test1 after defaulting to i: 0 test1 after hash assignment: 0 i = 2 test1 after defaulting to i: 0 test1 after hash assignment: 0 i = 3 test1 after defaulting to i: 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assigning from post fix if exists breaks local scoping?
by kcott (Archbishop) on Mar 28, 2014 at 18:56 UTC | |
by swinging_simian (Initiate) on Mar 28, 2014 at 19:04 UTC | |
by Anonymous Monk on Mar 28, 2014 at 19:47 UTC |