develooper Front page | perl.fwp | Postings from July 2006

Re: Naming the @{[]} operator

Thread Previous | Thread Next
From:
A. Pagaltzis
Date:
July 13, 2006 09:55
Subject:
Re: Naming the @{[]} operator
Message ID:
20060713165455.GY2620@klangraum
* Bart Lateur <bart.lateur@pandora.be> [2006-07-13 11:30]:
> On Thu, 13 Jul 2006 04:29:38 -0400, Chasecreek Systemhouse wrote:
> >What the advantage the above over this:
> >
> >perl -le 'print time'
> 
> Oh come on, you asked how to use @{[]}.

It’s a legitimate question.

Another use case:

    for( qw( 1 2 3 ) ) {
        $_ = $_ * $_; # contrived
        print "square: $_\n";
    }
    __END__
    Modification of a read-only value attempted at foo line 2.

as opposed to

    for( @{[ qw( 1 2 3 ) ]} ) {
        $_ = $_ * $_; # contrived
        print "square: $_\n";
    }
    __END__
    square: 1
    square: 4
    square: 9

In other words it’s also useful when you need to break aliasing
to make sure you’re operating on a modifiable copied scalar.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About