Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^7: Binary to decimal conversion

by Fletch (Chancellor)
on Dec 11, 2007 at 14:02 UTC ( #656408=note: print w/ replies, xml ) Need Help??


in reply to Re^6: Binary to decimal conversion
in thread Binary to decimal conversion

Because print takes a LIST and hence provides a list context to reverse which triggers the list context behavior from the latter (and a 1 element list reversed is indistinguishable from the original 1 element list for obvious reasons). Stick a scalar in there after the print, and/or store the reverse into a scalar temporary variable, and you'll see the behavior you're expecting.

The cake is a lie.
The cake is a lie.
The cake is a lie.


Comment on Re^7: Binary to decimal conversion
Select or Download Code
Replies are listed 'Best First'.
Re^8: Binary to decimal conversion
by ikegami (Pope) on Dec 11, 2007 at 19:09 UTC
    Said code (and then some):
    $\ = "\n"; print(my @a = reverse('hello')); # hello (order or scalars reversed) print(my $s = reverse('hello')); # olleh (order of chars reversed) print(reverse('hello')); # hello (order or scalars reversed) print(scalar(reverse('hello'))); # olleh (order of chars reversed) sub f(@) { return @_; } sub g($) { return @_; } print(f(reverse('hello')); # hello (order or scalars reversed) print(g(reverse('hello'))); # olleh (order of chars reversed)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://656408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-07-30 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls