I think that his implication was just a clarification of a subtlety that escapes many Perl novices.
The point is that you don't have to use the my() declaration between curly braces to define its scope within a block of code. You can use my() within the condition of an if/else block:
And the variable $name has the scope of that conditional.if ( (my $name = GetName()) =~ /^\w+$/) ) { print $name; }
You can also use the my() declaration in a loop control statement:
And the variable's scope is that of the loop. It was certainly a revelation for me, once upon a time...while (my $line = <>) { print $line; } foreach my $name (@people) { print $name; }
buckaduck
In reply to Re: Re: Re: Re: I need a simple explantion of the difference between my() and local()
by buckaduck
in thread I need a simple explantion of the difference between my() and local()
by Jemts
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |