Re: for $arrayref {...}
Luke Palmer skribis 2005-09-01 23:43 (+): I would probably say that scalars never automatically dereference. It's lists and hashes that automatically dereference/enreference. arrays That is, everything is a scalar, really, but if you have an @ or a % on the front of your variable, that means that you flatten yourself into specific kinds of contexts. sub foo (@bar) { ... } foo $aref; Here $aref is dereferenced because of the Array context. The scalar can't do this by itself, of course. Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: for $arrayref {...}
On 9/2/05, Juerd [EMAIL PROTECTED] wrote: Luke Palmer skribis 2005-09-01 23:43 (+): I would probably say that scalars never automatically dereference. It's lists and hashes that automatically dereference/enreference. arrays Yes, arrays, right. That is, everything is a scalar, really, but if you have an @ or a % on the front of your variable, that means that you flatten yourself into specific kinds of contexts. sub foo (@bar) { ... } foo $aref; Here $aref is dereferenced because of the Array context. The scalar can't do this by itself, of course. No, my view is that $foo and @foo are really the same kind of thing. They're both references to lists (yes, lists). So binding @bar := $aref is not doing anything special, it's just like binding two scalars. The only thing that makes @bar different from $aref is that in list context, @bar flattens out the list it's holding whereas $aref doesn't. Luke
multisub.arity?
Hi, multi foo ($a) {...} multi foo ($a, $b) {...} say foo.arity; # die? warn and return 0? warn and return undef? return 1|2? --Ingo -- Linux, the choice of a GNU | There are no answers, only generation on a dual AMD | cross-references. Athlon!|
Re: multisub.arity?
On Fri, Sep 02, 2005 at 05:56:39PM +0200, Ingo Blechschmidt wrote: : Hi, : : multi foo ($a) {...} : multi foo ($a, $b) {...} : : say foo.arity; : # die? warn and return 0? warn and return undef? return 1|2? How 'bout undef but 1..2? :-) Larry
undef but 1..2?
Hi, Larry Wall wrote: On Fri, Sep 02, 2005 at 05:56:39PM +0200, Ingo Blechschmidt wrote: : multi foo ($a) {...} : multi foo ($a, $b) {...} : : say foo.arity; : # die? warn and return 0? warn and return undef? return 1|2? How 'bout undef but 1..2? :-) Interesting, but now you have to elaborate a bit. :) I've thought there're two forms of the but operator: my $foo = Foo.new but { .bar($baz); .grtz = baka; }; $obj but SomeRole; # leaves $obj untouched and returns $obj with the SomeRole role # incorporated, i.e. .does(SomeRole) is true then 0 but true; # is really 0 but bool::true # works, as bool::true is a role 0 but 42; # error: Can't use 42 as a role Ok. But what about undef but 1..2? 1..2 isn't a role, right? So how can infix:but work with it? --Ingo, who has probably misunderstood your :-) :) -- Linux, the choice of a GNU | The future is here. It's just not widely generation on a dual AMD | distributed yet. -- William Gibson Athlon!|
Re: for $arrayref {...}
On Fri, Sep 02, 2005 at 09:24:52 +0200, Juerd wrote: sub foo (@bar) { ... } foo $aref; Here $aref is dereferenced because of the Array context. The scalar can't do this by itself, of course. my @bar := $aref; -- () Yuval Kogman [EMAIL PROTECTED] 0xEBD27418 perl hacker /\ kung foo master: /me kicks %s on the nose: neeyah! pgpMVoLstWjCP.pgp Description: PGP signature