[Melbourne-pm] Pls explain?
Mathew Robertson
mathew.robertson at netratings.com.au
Tue Oct 23 17:44:42 PDT 2007
>> #<<<<<<<<< CUT HERE >>>>>>>>>>>>
>> #!/usr/bin/perl -w
>> #
>> use strict;
>> use warnings;
>>
>> sub get_name_1
>> {
>> my ( $n, $backfill ) = @_;
>>
>> my $job_name = "backfill_" if $backfill;
>>
>
> This line above is like writing:
>
> my $a if $b;
>
> So the lexical variable $a only springs into existence if $b is true. Therefore
> (since $backfill isn't true)
>
why is it the same?
The "my $job_name" should be an isolated statement due to the "="
operator, ie: an lvalue is being created.
Thus "my $a if $b" doesn't have a lvalue until the "if" is true.
>> $job_name .= "migrate_$n";
>>
> this must be the global $job_name; hence the behaviour you see. There is a
> (lame) excuse for why you don't get strict errors and warnings, but I don't
> remember what it is, and personally I think it's a bug.
>
In any case $job_name would be undef on the first iteration, whether it
was global or local scoped. I'd be interested to know why a warning
isn't produced?
cheers,
Mathew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/melbourne-pm/attachments/20071024/6fbe5551/attachment.html
More information about the Melbourne-pm
mailing list