Re: Assigning anonymous hash to a list
Careful, the hounds are loose tonight! On Tue, Jul 30, 2013 at 10:36 PM, Hernan Lopes wrote: > sorry i meant 1 thing on the left and one thing on the right. Both are > lists and should be the same size. > > On 7/30/13, Hernan Lopes wrote: >> When you do that, you are implicitly saying: >> >> The thing on the left is equals the thing in the right. >> So, in the left you have 1 thing ( a list because of parenthesis ), >> and on the right, you have 2 things: string+object. >> >> Add parenthesis on the right and transform it into a list. >> >> After that perl will understand you are assinging the first thing on >> the list (from left) equals the first thing on the list (from right) >> and so on. >> >> []'s >> >> Hernan Lopes >> >> On 7/30/13, gvim wrote: >>> Can anyone explain why this works: >>> >>> my $ref = {a => 1, b => 2, c => 3}; >>> say $ref->{b}; # Result: 2 >>> >>> ... but this doesn't : >>> >>> my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; >>> say $ref->{b}; # Result: Use of uninitialized value >>> >>> Seems a little inconsistent. >>> >>> gvim >>> >> -- Best Regards, [Joseph] Christian Werner Sr C 360.920.7183 H 757.304.0502 Txt 757.304.0502
Re: Assigning anonymous hash to a list
sorry i meant 1 thing on the left and one thing on the right. Both are lists and should be the same size. On 7/30/13, Hernan Lopes wrote: > When you do that, you are implicitly saying: > > The thing on the left is equals the thing in the right. > So, in the left you have 1 thing ( a list because of parenthesis ), > and on the right, you have 2 things: string+object. > > Add parenthesis on the right and transform it into a list. > > After that perl will understand you are assinging the first thing on > the list (from left) equals the first thing on the list (from right) > and so on. > > []'s > > Hernan Lopes > > On 7/30/13, gvim wrote: >> Can anyone explain why this works: >> >> my $ref = {a => 1, b => 2, c => 3}; >> say $ref->{b}; # Result: 2 >> >> ... but this doesn't : >> >> my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; >> say $ref->{b}; # Result: Use of uninitialized value >> >> Seems a little inconsistent. >> >> gvim >> >
Re: Assigning anonymous hash to a list
ie: my ( $first_thing_on_the_left, $second_thing ) = ( "first something" , { second => 'something' } ); On 7/30/13, Hernan Lopes wrote: > When you do that, you are implicitly saying: > > The thing on the left is equals the thing in the right. > So, in the left you have 1 thing ( a list because of parenthesis ), > and on the right, you have 2 things: string+object. > > Add parenthesis on the right and transform it into a list. > > After that perl will understand you are assinging the first thing on > the list (from left) equals the first thing on the list (from right) > and so on. > > []'s > > Hernan Lopes > > On 7/30/13, gvim wrote: >> Can anyone explain why this works: >> >> my $ref = {a => 1, b => 2, c => 3}; >> say $ref->{b}; # Result: 2 >> >> ... but this doesn't : >> >> my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; >> say $ref->{b}; # Result: Use of uninitialized value >> >> Seems a little inconsistent. >> >> gvim >> >
Re: Assigning anonymous hash to a list
When you do that, you are implicitly saying: The thing on the left is equals the thing in the right. So, in the left you have 1 thing ( a list because of parenthesis ), and on the right, you have 2 things: string+object. Add parenthesis on the right and transform it into a list. After that perl will understand you are assinging the first thing on the list (from left) equals the first thing on the list (from right) and so on. []'s Hernan Lopes On 7/30/13, gvim wrote: > Can anyone explain why this works: > > my $ref = {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: 2 > > ... but this doesn't : > > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: Use of uninitialized value > > Seems a little inconsistent. > > gvim >
Re: Assigning anonymous hash to a list
On 07/30/2013 06:52 PM, Joseph Werner wrote: Hmmm. Yitzchak Scott-Thoennes, I recognize, Abigail I do not (perhaps I should?) So, Yitzchak, is this, in fact, a simple matter of operator precedence in that the ',' operator is of lower precedence than the assignment operator (absurd though that may seem) AND not a case of a scalar value (which is the result of a Perl expression involving a ',' operator) being offered to a list assignment? perldoc perlop shows the comma op has very low precedence. it allows for this: $foo = 1, $bar = 2 ; that does what you think it does, 2 assignments. the example in question breaks into 2 expressions connected by a comma (assignment in perl is still just an expression). the left expression does the assignment and the right expression has nowhere to go (hence its void context). as others (abigail too) have shown, warnings will catch useless data in void context. so parens around the right side changes where the comma binds to just inside the parens. now it assigns that list to the LHS list. note that the comma is now a list separator and not the scalar comma op. so this is absolutely a precedence issue and nothing else. the key is that assignment binds tighter than the comma. your eyes may say otherwise but perl (and abigail) knows better! :) thanx, uri -- Uri Guttman - The Perl Hunter The Best Perl Jobs, The Best Perl Hackers http://PerlHunter.com
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 4:12 PM, Yitzchak Scott-Thoennes wrote: > Yes, as was demonstrated clearly by someone with Deparse and someone > else by enabling warnings (sorry, forget who). Both Abigail :)
Re: Assigning anonymous hash to a list
> You can believe anything Abigail says. Hmmm.. . respect is an earned thing; You, Yitzchak, have earned my respect for reasons that transcend mere accuracy. Thank you for the day's lesson, -- Best Regards, [Joseph] Christian Werner Sr C 360.920.7183 H 757.304.0502 Txt 757.304.0502
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 06:52:32PM -0400, Joseph Werner wrote: > Hmmm. Yitzchak Scott-Thoennes, I recognize, Abigail I do not (perhaps > I should?) > > So, Yitzchak, is this, in fact, a simple matter of operator precedence > in that the ',' operator is of lower precedence than the assignment > operator (absurd though that may seem) AND not a case of a scalar > value (which is the result of a Perl expression involving a ',' > operator) being offered to a list assignment? > Because the comma is in scalar context (it's in void context, but that's a special case of scalar context), it will apply scalar context when it evaluates its arguments. Its leftmost argument is an assigment. Hence, the assignment will be evaluated in scalar context. On the LHS of the assignment is a list, which makes the assignment is list assignment (in scalar context). Because it's a list assignment, the RHS of the assignment is evaluated in list context. The difference between my ($str, $ref) = "text", { }; and my ($str, $ref) = ("text", { }); is precedence. In the former expression, the comma (the one following "text") is the top level operator. In the latter expression, the (list)assignment is the top level operator. Both expressions have a list assignment, but only the first expression has a comma in scalar (void) context. Abigail
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 3:52 PM, Joseph Werner wrote: > Hmmm. Yitzchak Scott-Thoennes, I recognize, Abigail I do not (perhaps > I should?) You can believe anything Abigail says. Well, except perhaps in the code comments here: http://perlmonks.org/?node_id=22319 > So, Yitzchak, is this, in fact, a simple matter of operator precedence > in that the ',' operator is of lower precedence than the assignment > operator (absurd though that may seem) AND not a case of a scalar > value (which is the result of a Perl expression involving a ',' > operator) being offered to a list assignment? Yes, as was demonstrated clearly by someone with Deparse and someone else by enabling warnings (sorry, forget who).
Re: Assigning anonymous hash to a list
Hmmm. Yitzchak Scott-Thoennes, I recognize, Abigail I do not (perhaps I should?) So, Yitzchak, is this, in fact, a simple matter of operator precedence in that the ',' operator is of lower precedence than the assignment operator (absurd though that may seem) AND not a case of a scalar value (which is the result of a Perl expression involving a ',' operator) being offered to a list assignment? Always interested in a learning opportunity, Christian On Tue, Jul 30, 2013 at 5:43 PM, Yitzchak Scott-Thoennes wrote: > On Tue, Jul 30, 2013 at 2:32 PM, Joseph Werner wrote: >> On Tue, Jul 30, 2013 at 4:51 PM, Abigail wrote: >>> By that argument, this is a scalar assignment as well: >>> >>> my ($i1, $i2, $i3) = (4, 5, 6); >> >> No, What you have done here is to assigned a list value to an array of >> assignable elements. > > There is *no* array anywhere there. There are two lists, though. > >> I am talking about the example at the top of this thread, which was a >> scalar assignment to a list of elements. > > I can see what you mean when you say that, but it is not correct terminology. > > Perl has two assignment operations, list assignment, and scalar assignment. > Which it is is determined purely based on what is on the left of the > assignment. -- Best Regards, [Joseph] Christian Werner Sr C 360.920.7183 H 757.304.0502 Txt 757.304.0502
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 2:32 PM, Joseph Werner wrote: > On Tue, Jul 30, 2013 at 4:51 PM, Abigail wrote: >> By that argument, this is a scalar assignment as well: >> >> my ($i1, $i2, $i3) = (4, 5, 6); > > No, What you have done here is to assigned a list value to an array of > assignable elements. There is *no* array anywhere there. There are two lists, though. > I am talking about the example at the top of this thread, which was a > scalar assignment to a list of elements. I can see what you mean when you say that, but it is not correct terminology. Perl has two assignment operations, list assignment, and scalar assignment. Which it is is determined purely based on what is on the left of the assignment.
Re: Assigning anonymous hash to a list
On 30 Jul 2013, at 22:32, Joseph Werner wrote: > No, What you have done here is to assigned a list value to an array of > assignable elements. > > I am talking about the example at the top of this thread, which was a > scalar assignment to a list of elements. You've seen what perl thinks of it (in the form of opcodes executed) and it isn't what you think it thinks. Please stop telling people it's raining when you're standing dry in the sunshine. Abigail is…Abigail. He's usually right. James
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 4:51 PM, Abigail wrote: > So? > > By that argument, this is a scalar assignment as well: > > my ($i1, $i2, $i3) = (4, 5, 6); > No, What you have done here is to assigned a list value to an array of assignable elements. I am talking about the example at the top of this thread, which was a scalar assignment to a list of elements. And sorry if my message was not clean; here I only make the point that the comma operator is a valid component of a Perl expression. >> >> The comma operator is a valid component of a Perl expression. >> >> my $str = 'text', {a => 1, b => 2, c => 3}; >> say $str; >> >> which gives: >> >> Useless use of anonymous hash ({}) in void context at test.pl line 5. >> text And here I refer to the subject expression of this thread. >> Again, this is a simple assignment of a scalar value to the first >> element of a list, precedence is not involved. > > > Bzzzt. Wrong. Again. > -- Best Regards, [Joseph] Christian Werner Sr C 360.920.7183 H 757.304.0502 Txt 757.304.0502
Re: Assigning anonymous hash to a list
gvim writes: > On 30/07/2013 20:09, Joseph Werner wrote: > > > It is because you are not assigning a list value to a list. You are > > assigning a scalar value that is the result of a ',' expression to > > the first element in the list. > > Got it. Nothing to do with the hashref. Should have used parens ... Yes! > ... to create list context. No -- you already had list context! But , has lower precedence than = does (see perldoc perlop). So your statement: my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; is parsed as first do this -- which is a list-context assignment: my ($str, $ref) = 'text' and then 'do' this -- which is just some data, in void context: {a => 1, b => 2, c => 3} The extra parens on the right don't change any context; they just restrict the comma to only operating inside those parens, rather than splitting up your statement in an unwanted place. Smylers -- Stop drug companies hiding negative research results. Sign the AllTrials petition to get all clinical research results published. Read more: http://www.alltrials.net/blog/the-alltrials-campaign/
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 04:33:33PM -0400, Joseph Werner wrote: > I still disagree. This is a straightforward assignment to the first > element of a list. > > In Perl, if you assign a scalar value to a list, the first variable in > the list will take that value, if it is assignable: > > my ($i1, $i2, $i3) = 4; > > say "\$i1 = ", $i1; > say "\$i2 = ", $i2; > say "\$i3 = ", $i3; > > which gives: > > $i1 = 4 > Use of uninitialized value $i2 in say at test.pl line 11. > $i2 = > Use of uninitialized value $i3 in say at test.pl line 12. > $i3 = > > Here I have assigned the scalar value 4 to the list element $i1, which > is assignable. So? By that argument, this is a scalar assignment as well: my ($i1, $i2, $i3) = (4, 5, 6); as you have assigned the scalar value 4 to list element $i1. my ($i1, $i2, $i3) = sub {wantarray ? "list" : "scalar"} -> (); say $i1; __END__ list $i2 and $i3 are undefined, $i1 contains the word "list", because Perl thinks, unlike you, that it's a list assignment. > > The comma operator is a valid component of a Perl expression. > > my $str = 'text', {a => 1, b => 2, c => 3}; > say $str; > > which gives: > > Useless use of anonymous hash ({}) in void context at test.pl line 5. > text > > Again, this is a simple assignment of a scalar value to the first > element of a list, precedence is not involved. Bzzzt. Wrong. Again. Here, due to the absense of parens around '$str', there's *NO* list on the LHS of the assignment. And that makes it a scalar assignment: $ perl -MO=Terse -e 'my $str = "text", { }' LISTOP (0x9eac898) leave [1] OP (0x9eac8b8) enter COP (0x9eac970) nextstate LISTOP (0x9eac930) list OP (0x9ea28a0) pushmark -> BINOP (0x9eaca58) sassign SVOP (0x9eacb08) const PV (0x9ea6b88) "text" OP (0x9eabbf0) padsv [1] LISTOP (0x9eac9a8) anonhash OP (0x9ea20c0) pushmark -e syntax OK $ Note the line "BINOP (0x9eaca58) sassign". *s*assign. Not *a*assign. Which you would get if you write "my ($str)": $ perl -MO=Terse -e 'my ($str) = "text", { }' LISTOP (0x8475d30) leave [1] OP (0x8525d30) enter COP (0x8476970) nextstate LISTOP (0x84768d0) list OP (0x846c8a0) pushmark -> BINOP (0x8476950) aassign [2] UNOP (0x84769a8) null [146] OP (0x8476b40) pushmark SVOP (0x8476b08) const PV (0x8470b88) "text" UNOP (0x8476a58) null [146] OP (0x846c0c0) pushmark OP (0x8475bf0) padsv [1] LISTOP (0x8476930) anonhash OP (0x84768b8) pushmark -e syntax OK $ > > Christian > > On Tue, Jul 30, 2013 at 3:49 PM, Abigail wrote: > > On Tue, Jul 30, 2013 at 03:34:48PM -0400, Joseph Werner wrote: > >> I disagree. > >> > >> This is a straightforward assignment to the first element of a list. > >> Precedence is not involved. A scalar assignment vs a list assignment > >> is the issue. > >> > > > > > > Thank you for playing. > > > > > > You are right it's straighforward, but you're wrong that it's scalar > > assignment vs list assignment. > > > > The fact there's "my ($str, $ref)" on the LHS of the assignment makes > > that Perl considers this a list assignment: > > > > > > $ perl -MO=Terse -e 'my ($str, $ref) = "text", {a => 1, b => 2, c => 3}' > > LISTOP (0x100324de0) leave [1] > > OP (0x100324e20) enter > > COP (0x100324d90) nextstate > > LISTOP (0x100301f10) list > > OP (0x100301ee0) pushmark > > BINOP (0x1003093c0) aassign [3] > > UNOP (0x100309950) null [148] > > OP (0x100309390) pushmark > > SVOP (0x100309d90) const PV (0x1008143c0) "text" > > UNOP (0x100329530) null [148] > > OP (0x100329570) pushmark > > OP (0x1003096e0) padsv [1] > > OP (0x100309600) padsv [2] > > LISTOP (0x100309460) anonhash > > OP (0x1003094a0) pushmark > > SVOP (0x100309400) const PV (0x100814408) "a" > > SVOP (0x100309430) const IV (0x1008143f0) 1 > > SVOP (0x1003094d0) const PV (0x100814048) "b" > > SVOP (0x100309500) const IV (0x1008143a8) 2 > > SVOP (0x100309530) const PV (0x100814378) "c" > > SVOP (0x100309560) const IV (0x100814390) 3 > > -e syntax OK > > $ > > > > > > Note the line: BINOP (0x1003093c0) aassign [3], and compare: > > > > $ perl -MO=Terse -e 'my ($str, $ref) = ("text", {a => 1, b => 2, c => 3})' > > LISTOP (0x100324d90) leave [1] > > OP (0x100324dd0) enter > > COP (0x100324d40) nextstate > > BINOP (0x100309570) aassign [3] > > UNOP (0x100301f10) null [148] > > OP (0x100301ee0) pushmark > > SVOP (0x100309d90) const PV (0x1008143c0) "text" > > LISTOP (0x
Re: Assigning anonymous hash to a list
I still disagree. This is a straightforward assignment to the first element of a list. In Perl, if you assign a scalar value to a list, the first variable in the list will take that value, if it is assignable: my ($i1, $i2, $i3) = 4; say "\$i1 = ", $i1; say "\$i2 = ", $i2; say "\$i3 = ", $i3; which gives: $i1 = 4 Use of uninitialized value $i2 in say at test.pl line 11. $i2 = Use of uninitialized value $i3 in say at test.pl line 12. $i3 = Here I have assigned the scalar value 4 to the list element $i1, which is assignable. The comma operator is a valid component of a Perl expression. my $str = 'text', {a => 1, b => 2, c => 3}; say $str; which gives: Useless use of anonymous hash ({}) in void context at test.pl line 5. text Again, this is a simple assignment of a scalar value to the first element of a list, precedence is not involved. Christian On Tue, Jul 30, 2013 at 3:49 PM, Abigail wrote: > On Tue, Jul 30, 2013 at 03:34:48PM -0400, Joseph Werner wrote: >> I disagree. >> >> This is a straightforward assignment to the first element of a list. >> Precedence is not involved. A scalar assignment vs a list assignment >> is the issue. >> > > > Thank you for playing. > > > You are right it's straighforward, but you're wrong that it's scalar > assignment vs list assignment. > > The fact there's "my ($str, $ref)" on the LHS of the assignment makes > that Perl considers this a list assignment: > > > $ perl -MO=Terse -e 'my ($str, $ref) = "text", {a => 1, b => 2, c => 3}' > LISTOP (0x100324de0) leave [1] > OP (0x100324e20) enter > COP (0x100324d90) nextstate > LISTOP (0x100301f10) list > OP (0x100301ee0) pushmark > BINOP (0x1003093c0) aassign [3] > UNOP (0x100309950) null [148] > OP (0x100309390) pushmark > SVOP (0x100309d90) const PV (0x1008143c0) "text" > UNOP (0x100329530) null [148] > OP (0x100329570) pushmark > OP (0x1003096e0) padsv [1] > OP (0x100309600) padsv [2] > LISTOP (0x100309460) anonhash > OP (0x1003094a0) pushmark > SVOP (0x100309400) const PV (0x100814408) "a" > SVOP (0x100309430) const IV (0x1008143f0) 1 > SVOP (0x1003094d0) const PV (0x100814048) "b" > SVOP (0x100309500) const IV (0x1008143a8) 2 > SVOP (0x100309530) const PV (0x100814378) "c" > SVOP (0x100309560) const IV (0x100814390) 3 > -e syntax OK > $ > > > Note the line: BINOP (0x1003093c0) aassign [3], and compare: > > $ perl -MO=Terse -e 'my ($str, $ref) = ("text", {a => 1, b => 2, c => 3})' > LISTOP (0x100324d90) leave [1] > OP (0x100324dd0) enter > COP (0x100324d40) nextstate > BINOP (0x100309570) aassign [3] > UNOP (0x100301f10) null [148] > OP (0x100301ee0) pushmark > SVOP (0x100309d90) const PV (0x1008143c0) "text" > LISTOP (0x1003093c0) anonhash > OP (0x100309400) pushmark > SVOP (0x100309950) const PV (0x100814450) "a" > SVOP (0x100309390) const IV (0x100814408) 1 > SVOP (0x100309430) const PV (0x1008143f0) "b" > SVOP (0x100309460) const IV (0x100814048) 2 > SVOP (0x100309490) const PV (0x1008143a8) "c" > SVOP (0x1003094c0) const IV (0x100814378) 3 > UNOP (0x100329530) null [148] > OP (0x100329570) pushmark > OP (0x1003096e0) padsv [1] > OP (0x100309600) padsv [2] > -e syntax OK > $ > > > > Abigail -- Best Regards, [Joseph] Christian Werner Sr C 360.920.7183 H 757.304.0502 Txt 757.304.0502
Re: isolating thread-unsafe modules
On 30/07/2013 20:38, DAVID HODGKINSON wrote: On 30 Jul 2013, at 14:54, David Cantrell wrote: Parallel::ForkManager has some (evil, hacky*) support for returning data from a forked child to the parent. And I've used it. Works fine. So have I, to work around an incompatible change in perl 5.18. It's not exactly a solution that I'm comfortable using though. For one thing, an evil-doer could potentially exploit it to spoof the returned data. Doesn't particularly matter in my case, but could in some others. -- David Cantrell | http://www.cantrell.org.uk/david engineer: n. one who, regardless of how much effort he puts in to a job, will never satisfy either the suits or the scientists
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 07:54:46PM +0100, gvim wrote: > Can anyone explain why this works: > > my $ref = {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: 2 > > ... but this doesn't : > > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: Use of uninitialized value > > Seems a little inconsistent. You could have asked Perl $ perl -we 'my ($str, $ref) = "text", {a => 1, b => 2, c => 3}' Useless use of anonymous hash ({}) in void context at -e line 1. $ Abigail
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 03:34:48PM -0400, Joseph Werner wrote: > I disagree. > > This is a straightforward assignment to the first element of a list. > Precedence is not involved. A scalar assignment vs a list assignment > is the issue. > Thank you for playing. You are right it's straighforward, but you're wrong that it's scalar assignment vs list assignment. The fact there's "my ($str, $ref)" on the LHS of the assignment makes that Perl considers this a list assignment: $ perl -MO=Terse -e 'my ($str, $ref) = "text", {a => 1, b => 2, c => 3}' LISTOP (0x100324de0) leave [1] OP (0x100324e20) enter COP (0x100324d90) nextstate LISTOP (0x100301f10) list OP (0x100301ee0) pushmark BINOP (0x1003093c0) aassign [3] UNOP (0x100309950) null [148] OP (0x100309390) pushmark SVOP (0x100309d90) const PV (0x1008143c0) "text" UNOP (0x100329530) null [148] OP (0x100329570) pushmark OP (0x1003096e0) padsv [1] OP (0x100309600) padsv [2] LISTOP (0x100309460) anonhash OP (0x1003094a0) pushmark SVOP (0x100309400) const PV (0x100814408) "a" SVOP (0x100309430) const IV (0x1008143f0) 1 SVOP (0x1003094d0) const PV (0x100814048) "b" SVOP (0x100309500) const IV (0x1008143a8) 2 SVOP (0x100309530) const PV (0x100814378) "c" SVOP (0x100309560) const IV (0x100814390) 3 -e syntax OK $ Note the line: BINOP (0x1003093c0) aassign [3], and compare: $ perl -MO=Terse -e 'my ($str, $ref) = ("text", {a => 1, b => 2, c => 3})' LISTOP (0x100324d90) leave [1] OP (0x100324dd0) enter COP (0x100324d40) nextstate BINOP (0x100309570) aassign [3] UNOP (0x100301f10) null [148] OP (0x100301ee0) pushmark SVOP (0x100309d90) const PV (0x1008143c0) "text" LISTOP (0x1003093c0) anonhash OP (0x100309400) pushmark SVOP (0x100309950) const PV (0x100814450) "a" SVOP (0x100309390) const IV (0x100814408) 1 SVOP (0x100309430) const PV (0x1008143f0) "b" SVOP (0x100309460) const IV (0x100814048) 2 SVOP (0x100309490) const PV (0x1008143a8) "c" SVOP (0x1003094c0) const IV (0x100814378) 3 UNOP (0x100329530) null [148] OP (0x100329570) pushmark OP (0x1003096e0) padsv [1] OP (0x100309600) padsv [2] -e syntax OK $ Abigail
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 08:23:30PM +0100, Adrian Lai wrote: > my ($a, $b) = 'x', 'y'; > say $b; # undef > > my ($a, $b) = ('x', 'y'); > say $b; # y > > I assume Perl interprets as (my ($a, $b) = 'x'), 'y'. > You don't have to assume, you can ask Perl. $ perl -MO=Deparse,-p -e 'my ($a, $b) = "x", "y"' ((my($a, $b) = 'x'), '???'); $ Abigail
Re: Assigning anonymous hash to a list
On Tue, Jul 30, 2013 at 08:15:06PM +0100, Peter Flanigan wrote: > On 30/07/13 19:54, gvim wrote: > > Can anyone explain why this works: > > > > my $ref = {a => 1, b => 2, c => 3}; > > say $ref->{b}; # Result: 2 > > > > ... but this doesn't : > > > > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > > say $ref->{b}; # Result: Use of uninitialized value > > > > Seems a little inconsistent. > > > > gvim > > > > > > Try > >my ($str, $ref) = ( 'text', {a => 1, b => 2, c => 3} ); > > The extra set of brackets force evaluation in a list context List context is caused (indirectly) by the parens on the LHS of the assignment. The added parens on the RHS do diddly squat for context. They're there for *precedence*. Their act is played at parse time, and they don't come back for an encore at compile time, nor run time. Abigail
Re: isolating thread-unsafe modules
On 30 Jul 2013, at 14:54, David Cantrell wrote: > On Sun, Jul 28, 2013 at 10:02:25PM +0100, Bob MacCallum wrote: > >> Good question - I have always hacked something with fork in the past but it >> just seemed so simple with Thread::Queue and threads. I've never needed >> much IPC in the past. > > Parallel::ForkManager has some (evil, hacky*) support for returning data > from a forked child to the parent. And I've used it. Works fine. > > * the right sort of evil and hacky though > > -- > David Cantrell | Cake Smuggler Extraordinaire > >fdisk format reinstall, doo-dah, doo-dah; >fdisk format reinstall, it's the Windows way
Re: Assigning anonymous hash to a list
I disagree. This is a straightforward assignment to the first element of a list. Precedence is not involved. A scalar assignment vs a list assignment is the issue. Christian (oh boy, call out the hounds...) On Tue, Jul 30, 2013 at 3:19 PM, Paul LeoNerd wrote: > On Tue, 30 Jul 2013 19:54:46 +0100 > gvim wrote: > >> my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > > Precedence. > > This parses as > > ( my ( $str, $ref ) = 'text' ), { a => 1, b => 2, c => 3 }; > > To make it work as you expect use parens on the RHS as well: > > my ( $str, $ref ) = ( 'text', { a => 1, b => 2, c => 3 } ); > > -- > Paul "LeoNerd" Evans > > leon...@leonerd.org.uk > ICQ# 4135350 | Registered Linux# 179460 > http://www.leonerd.org.uk/ -- Best Regards, [Joseph] Christian Werner Sr C 360.920.7183 H 757.304.0502 Txt 757.304.0502
Re: Assigning anonymous hash to a list
On 30/07/2013 20:11, Mark Stringer wrote: Not sure why it's inconsistent. This works as you'd expect. Note the parens. my ($str, $ref) = ('text', {a => 1, b => 2, c => 3}); Mark I'm confusing arg lists with list assignment. gvim
Re: Assigning anonymous hash to a list
On 30 July 2013 19:54, gvim wrote: > Can anyone explain why this works: > > my $ref = {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: 2 > > ... but this doesn't : > > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: Use of uninitialized value > > Seems a little inconsistent. It's not inconsistent. Just because your language can do assignment doesn't mean it can do destructuring bind. As it happens, Perl *can* do destructuring bind. You want parentheses around the list though: my ($str, $ref) = ('text', {a => 1, b => 2, c => 3}); say $ref->{b}; (Your line parses the hash reference in void context, as you'd see if you're using warnings.) osf'
Re: Assigning anonymous hash to a list
my ($a, $b) = 'x', 'y'; say $b; # undef my ($a, $b) = ('x', 'y'); say $b; # y I assume Perl interprets as (my ($a, $b) = 'x'), 'y'. Adrian. On 30 July 2013 19:54, gvim wrote: > Can anyone explain why this works: > > my $ref = {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: 2 > > ... but this doesn't : > > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: Use of uninitialized value > > Seems a little inconsistent. > > gvim >
Re: Assigning anonymous hash to a list
On 30/07/2013 20:09, Joseph Werner wrote: It is because you are not assigning a list value to a list. You are assigning a scalar value that is the result of a ',' expression to the first element in the list. Hope this helps. Christian Got it. Nothing to do with the hashref. Should have used parens to create list context. gvim
Re: Assigning anonymous hash to a list
On Tue, 30 Jul 2013 19:54:46 +0100 gvim wrote: > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; Precedence. This parses as ( my ( $str, $ref ) = 'text' ), { a => 1, b => 2, c => 3 }; To make it work as you expect use parens on the RHS as well: my ( $str, $ref ) = ( 'text', { a => 1, b => 2, c => 3 } ); -- Paul "LeoNerd" Evans leon...@leonerd.org.uk ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/ signature.asc Description: PGP signature
Re: Assigning anonymous hash to a list
On 30/07/13 19:54, gvim wrote: > Can anyone explain why this works: > > my $ref = {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: 2 > > ... but this doesn't : > > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: Use of uninitialized value > > Seems a little inconsistent. > > gvim > > Try my ($str, $ref) = ( 'text', {a => 1, b => 2, c => 3} ); The extra set of brackets force evaluation in a list context -- Regards
Re: Assigning anonymous hash to a list
Don't you need parentheses on both sides of that assignment? Sent from Samsung Mobile Original message From: gvim Date: To: London PM Subject: Assigning anonymous hash to a list Can anyone explain why this works: my $ref = {a => 1, b => 2, c => 3}; say $ref->{b}; # Result: 2 ... but this doesn't : my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; say $ref->{b}; # Result: Use of uninitialized value Seems a little inconsistent. gvim
Re: Assigning anonymous hash to a list
Not sure why it's inconsistent. This works as you'd expect. Note the parens. my ($str, $ref) = ('text', {a => 1, b => 2, c => 3}); Mark On 07/30/2013 07:54 PM, gvim wrote: Can anyone explain why this works: my $ref = {a => 1, b => 2, c => 3}; say $ref->{b}; # Result: 2 ... but this doesn't : my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; say $ref->{b}; # Result: Use of uninitialized value Seems a little inconsistent. gvim
Re: Assigning anonymous hash to a list
ITYM, my ($str, $ref) = ('text', {a => 1, b => 2, c => 3}); say $ref->{b}; # Result: 2 extra () are needed. On Tue, Jul 30, 2013 at 7:54 PM, gvim wrote: > Can anyone explain why this works: > > my $ref = {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: 2 > > ... but this doesn't : > > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: Use of uninitialized value > > Seems a little inconsistent. > > gvim >
Re: Assigning anonymous hash to a list
It is because you are not assigning a list value to a list. You are assigning a scalar value that is the result of a ',' expression to the first element in the list. Hope this helps. Christian On Tue, Jul 30, 2013 at 2:54 PM, gvim wrote: > Can anyone explain why this works: > > my $ref = {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: 2 > > ... but this doesn't : > > my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; > say $ref->{b}; # Result: Use of uninitialized value > > Seems a little inconsistent. > > gvim -- Best Regards, [Joseph] Christian Werner Sr C 360.920.7183 H 757.304.0502 Txt 757.304.0502
Assigning anonymous hash to a list
Can anyone explain why this works: my $ref = {a => 1, b => 2, c => 3}; say $ref->{b}; # Result: 2 ... but this doesn't : my ($str, $ref) = 'text', {a => 1, b => 2, c => 3}; say $ref->{b}; # Result: Use of uninitialized value Seems a little inconsistent. gvim
Re: isolating thread-unsafe modules
On Sun, Jul 28, 2013 at 10:02:25PM +0100, Bob MacCallum wrote: > Good question - I have always hacked something with fork in the past but it > just seemed so simple with Thread::Queue and threads. I've never needed > much IPC in the past. Parallel::ForkManager has some (evil, hacky*) support for returning data from a forked child to the parent. * the right sort of evil and hacky though -- David Cantrell | Cake Smuggler Extraordinaire fdisk format reinstall, doo-dah, doo-dah; fdisk format reinstall, it's the Windows way