Hosen1989 has asked for the wisdom of the Perl Monks concerning the following question:
Dear ALL,
I was debug some old dirty script of mine (which without strict nor warnings ^_^), and faced this issue:
As you can see in case(1), variable $me had been declared more than once, and to output of this script is: []
#----------[ CASE(1) ]----------# my $v_place = 'home'; my $me = 'moving'; my $me = 'at home' if($v_place =~ m/^home/); my $me = 'at work' if($v_place =~ m/^work/); print "[$me]"; __END__ output: [] #-------------------------------#
But after correct the declaration problem as in case(2), we got the correct output: [at home].
#----------[ CASE(2) ]----------# my $v_place = 'home'; my $me = 'moving'; $me = 'at home' if($v_place =~ m/^home/); $me = 'at work' if($v_place =~ m/^work/); print "[$me]"; __END__ output: [at home] #-------------------------------#
Now,can any monk explain me just what happen here?
BR
Hosen
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "my" declaration problem
by Eily (Monsignor) on Apr 25, 2017 at 11:56 UTC | |
|
Re: "my" declaration problem
by davies (Monsignor) on Apr 25, 2017 at 11:29 UTC | |
|
Re: "my" declaration problem
by talexb (Chancellor) on Apr 25, 2017 at 14:32 UTC | |
|
Re: "my" declaration problem
by karlgoethebier (Abbot) on Apr 26, 2017 at 11:53 UTC | |
|
Re: "my" declaration problem
by Anonymous Monk on Apr 25, 2017 at 11:29 UTC | |
|
Re: "my" declaration problem
by LanX (Saint) on Apr 25, 2017 at 17:02 UTC | |
by Anonymous Monk on Apr 25, 2017 at 18:57 UTC | |
by LanX (Saint) on Apr 25, 2017 at 20:06 UTC | |
by Corion (Patriarch) on Apr 25, 2017 at 20:30 UTC | |
by LanX (Saint) on Apr 25, 2017 at 20:38 UTC | |
|