gri6507 has asked for the wisdom of the Perl Monks concerning the following question:
I am taking over maintenance of some Perl code which was written by a, shall we say, Perl non-expert. However, this person did have a strong C background. I believe that caused him to write a line of Perl code which currently has me baffled. Here's the relevant section:
use warnings; use strict; my $foo = "bar"; DoIt(); sub DoIt { my $it = shift // $foo; # Given the C background of the author, I can see why the line was + written as is. However, it was supposed to be # my $it = shift; // $foo print "it is '$it'\n"; }
Oddly, the output is it is 'bar', although I do not understand why. Can someone please enlighten me what the line in question actually does?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange syntax question
by chromatic (Archbishop) on Aug 14, 2013 at 16:15 UTC | |
|
Re: Strange syntax question
by Utilitarian (Vicar) on Aug 14, 2013 at 16:15 UTC | |
|
Re: Strange syntax question
by choroba (Cardinal) on Aug 14, 2013 at 16:16 UTC | |
|
Re: Strange syntax question
by betterworld (Curate) on Aug 14, 2013 at 17:16 UTC | |
|
Re: Strange syntax question (perlop // dor)
by Anonymous Monk on Aug 14, 2013 at 16:14 UTC | |
|
Re: Strange syntax question
by Laurent_R (Canon) on Aug 14, 2013 at 18:45 UTC | |
|
Re: Strange syntax question
by marinersk (Priest) on Aug 14, 2013 at 17:34 UTC | |
by AnomalousMonk (Archbishop) on Aug 14, 2013 at 23:44 UTC |