---------- Original Message ----------------------------------
From: [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
Date: Wed, 30 Jan 2002 17:03:45 +0100
>On Wed, Jan 30, 2002 at 04:46:28PM +0100, Joerg Ziefle wrote:
>> ---------- Original Message ----------------------------------
>> From: [EMAIL PROTECTED]
>> Reply-To: [EMAIL PROTECTED]
>> Date: Wed, 30 Jan 2002 16:24:20 +0100
>>
>> >On Wed, Jan 30, 2002 at 03:55:32PM +0100, Joerg Ziefle wrote:
>> >> perl -e 'print "Current time is: @{[scalar localtime]}\n"'
>> >>
>> >> Note the obvious difference to:
>> >>
>> >> perl -e 'print "Current time is: @{[localtime]}\n"'
>> >
>> >
>> >Eh, it's the "scalar" that makes the scalar evaluation in those
>> >examples. After all "@{[scalar localtime]}" gives the result
>> >of 'localtime' in scalar context, not list context as you suggest.
>>
>> Ok, got me :)
>> The example was not the best and would have better been something along
>>
>> perl -e 'print "1 + 3 = ${\(1+3)}\n"'
>
>That would not be a very good example, and 1 + 3 is 4 in both scalar
>and list context.
>
>> BTW, can you think of a clunkier way to get the name of the current script as
>>
>> print "Call me $${\localtime} darling.\n"
>>
>> (and with some luck, that even fails :)?
>
>I fail to understand what you mean.
Consider this example program:
$\ = '
';
sub foo { return qw/1234 4567/ }
sub bar { return qw/1 2 / }
print "Call me $${\foo} darling.";
print "Call me $${\bar} darling.";
"bazbaz" =~ /(az)(ba)/;
print "Call me $${\bar} darling.";
__END__
Call me darling.
Call me darling.
Call me ba darling.
See what I mean?
Same with localtime:
localtime is called in list context and returns a list as follows:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
>From this list, the last element, $isdst ("is daylight saving time", currently 0) is
>taken in the expression
$${\localtime}
so at the moment, this gets
$0
Imagine the time has come that $isdst gets 1, then this expression reads
$1
which has quite another meaning.
Joerg