in reply to My, what is "my" doing here?
my, in this context, is of course an erroneous “bareword.”
Not at all. In Perl, declarations can simply used as expressions, they return the variables they declare.
If my was a bareword here, it would violate the "no two terms in a row" rule:
$ perl -ce '"my" $y' Scalar found where operator expected at -e line 1, near ""my" $y" (Missing operator before $y?)
It is perfectly legal to write things like
say my $x = 5;
Which declares variable $x, returns its value, and then prints it, followed by a newline.
I don't see the reason for using such a declaration in the if-statement without any initialization (it will always be undef), but it is perfectly legal.
|
|---|