On Wed, Jan 30, 2002 at 03:55:32PM +0100, Joerg Ziefle wrote:
> 
> Not to forget scalar evaluation within strings:
> 
>    "${\(<foo>)}"
> 
> as in:
> 
>    perl -e 'print "Current time is: ${\(scalar localtime)}\n"'
> 
> (the parens could as well have been omitted)
> 
> as opposed to the array evaluation
> 
>    "@{[<foo>]}"
> 
> as in:
> 
>    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.

And you even need the 'scalar' if you are using ${\(EXPR)}, as
\ doesn't propagate context; it provides list context.


    #!/usr/bin/perl

    use strict;
    use warnings 'all';

    sub context {wantarray ? "LIST" : "SCALAR"}

    print "${\context}\n";
    __END__
    LIST


This makes the "${\(EXPR)}" not very useful; one could as well use
"@{[EXPR]}" - which not only saves a keystroke, but is more symmetric.



Abigail

Reply via email to