Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Unpack Vector Weirdness

by Vynce (Friar)
on Oct 10, 2005 at 20:05 UTC ( [id://498929]=perlquestion: print w/replies, xml ) Need Help??

Vynce has asked for the wisdom of the Perl Monks concerning the following question:

So I've no idea why, but assignment to a scalar variable seems to change some lvalues.

To wit, warning the return of a particular sub yields a different warning that assigning that value to a scalar and warning that scalar. I cannot fathom why.

Any ideas?

#!/usr/bin/perl ###=- Unpack Vector Weirdness use strict; sub string { return (reverse (unpack ('b8', $_[0]))) } sub showoff { my $vec = shift; my $str; warn 'vvv'; warn string($vec); warn ($str = string($vec)); warn '^^^'; } for my $pass (0..7) { my $vec = int(rand(200)); showoff $vec; }

thanks,
Vynce
.

update:
yes, i know return (unpack ('B8', $_[0])) does what i want, but my question is why the original doesn't.

Replies are listed 'Best First'.
Re: Unpack Vector Weirdness
by runrig (Abbot) on Oct 10, 2005 at 20:16 UTC
    reverse has different behaviors in list vs. scalar context. Your first usage is in list context, the second (due to the assignment) is in scalar context.
      oh, creepy weird. that makes sense, i guess, but even knowing reverse had different behaviors by context, i didn't spot the context shift. thanks.
      .

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://498929]
Approved by chester
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found