Re: print statement creates key in hash with reference to empty array??
Anno Siegel schreef:
> Dr.Ruud:
>> Abigail:
>>> Dr.Ruud:
>>>> $ echo 'if( exists $hash{$key} ) { print "$hash($key)\n"; }' \
>>>> | perl -MO=Deparse,-x7
>>>>
>>>> exists $hash{$key} and do {
>>>> print "$hash($key)\n"
>>>> };
>>>>
>>>> I don't know why the do-block is needed.
>>>
>>> Because the then part of an if statement is a block. 'do {}' turns a
>>> block into an expression.
>>
>> I still don't see why it isn't 'cleaned up' further in the special
>> case that the expression is one statement. As you can deduce, I
>> assume that the "do{}" is never necessary around a single statement,
>> that "()" is sufficient.
>
> No, the "do{}"s are necessary, there *must* be a statement in this
> place. It's just that the DWIM mechanism inserts them for you in many
> situations where little else would make sense. What deparse shows is
> what perl actually compiles.
>From an earlier post:
$ echo 'print "$hash{$key}\n" if exists $hash{$key};' \
| perl -MO=Deparse,-x7
exists $hash{$key} and print "$hash{$key}\n";
That doesn't get a do{}.
> Deparse can't very well suppress them either, once they're there.
And I just wondered why not, for cases like this one.
--
Affijn, Ruud
"Gewoon is een tijger."
.
Relevant Pages
- Re: print statement creates key in hash with reference to empty array??
... Abigail: ... | perl -MO=Deparse,-x7 ... >> I don't know why the do-block is needed. ... "Gewoon is een tijger." ... (comp.lang.perl.misc) - Re: Which Counter is Perfect?
... His basic program opens the data file twice - once for reading, ... looking up the 'sysopen' function in the Perl ... Abigail ... (comp.lang.perl.misc) - Re: regex error
... Brendon Caligari wrote on MMMMLIII ... :} Abigail wrote: ... :}> Perl tries to compile a regexp containing some kind of syntax error. ... (comp.lang.perl.misc) - Re: Need help with froogle and cart id prob
... Sorry Abigail, I plead ignorance and hey, what can I say, I need help. ... > `' I'm currently trying to put a product page on Froogle. ... > This language is about the language Perl. ... > of software that happen to be written in Perl. ... (comp.lang.perl.misc) - Re: Is Perl open source?
... >> Generalizing is seldomly correct. ... > with hard real-time requirements in Perl is certifiable. ... Didn't Abigail just say that you shouldn't generalize? ... (comp.lang.perl.misc) |
|