method interpolation
Uri Guttman
uri at stemsystems.com
Wed Feb 1 16:27:30 GMT 2006
>>>>> "PM" == Paul Makepeace <london.pm.org at paulm.com> writes:
PM> Je 2006-02-01 13:24:38 +0000, Iain Tatch skribis:
>> On 01/02/06, Dirk Koopman <djk at tobit.co.uk> wrote:
>>
>> > My brain is failing me. Is there some incantation (probably including
>> > {}) that allows one to do something like:
>> >
>> > print "This is $syiq->UNIQID";
>>
>> warn "Ugly code follows:";
>> print "This is ${\( $syiq->UNIQID )}\n";
PM> The "canonical" way which is basically the same but with a list
PM> context is,
PM> print "This is @{[ $sys->UNIQ_ID ]}";
actually they are both in list context. this is a known bug (or
undocumented feature) and has been known for a good long while.
#!/usr/local/bin/perl
sub context {
return wantarray ? 'LIST' : 'SCALAR' ;
}
print "array is @{[context()]} context\n" ;
print "scalar is ${\context()} context\n" ;
array is LIST context
scalar is LIST context
same output for all of these:
This is perl, v5.8.6 built for sun4-solaris
This is perl, v5.6.1 built for sun4-solaris
This is perl, version 5.004_04 built for sun4-solaris
uri
--
Uri Guttman ------ uri at stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
More information about the london.pm
mailing list