Re: Naming the @{[]} operator
"A. Pagaltzis" <[email protected]> Thu, 13 Jul 2006 18:54:55 +0200
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <20060713165455.GY2620@klangraum> |
* Bart Lateur <[email protected]> [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/>