Re: "Secret" operators

Georg Moritz <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
From the keyboard of [email protected] [01.02.05,11:15]:

> Can I get that just a little slower?
>
>  $b = () = /u/g;
>
> is the same as:
>
>    @a = /u/g;
>    $b = @a;

it's not the same.

perl -le '$_="foo"; print $b =()= /o/g'
2
perl -le '$_="foo"; print @b =()= /o/g'

perl -le '$_="foo"; print /o/g'
oo

The brackets in =()= means something like 'here would have been n elements,
were you interested'. There's no list, only list context.

-gg-

> I understand what happens, but it appears to be assigning to an empty list
> - is that filling up the list, so to speak?  Or is it just that it makes
> the 'result' of /u/g assign in array/list context and then that, assigned
> in scalar context to $b gives the list/array count.
>
> I tried to explain this once and I had to resort to 'and then <mumble
> mumble> and in scalar context, we get the count of the elements in $b!'
>
> a
>
> Andy Bach, Sys. Mangler
> Internet: [email protected]
> VOICE: (608) 261-5738  FAX 264-5932
>
> "Bugs happen. A bug is a test case you haven't written yet."
> Mark Pilgrim
>

-- 
_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s,/,($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e,e && print}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.