Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Re: Re: Re: sort mechanism

by extremely (Priest)
on Apr 07, 2001 at 00:01 UTC ( #70577=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: sort mechanism
in thread sort mechanism

The equality operators apply scalar context to both sides. Try this out and see. Operators apply context. I don't think they often respond to it but with perl anything is possible =)
my @a = keys %env; my @b = values %env; my @c = ( "equal", "a > b", "b > a" ); print ($c[@a<=>@b]),$/;

No really, damn good band names... =)

$you = new YOU;
honk() if $you->love(perl)

Replies are listed 'Best First'.
Something Strange is Afoot Here
by McD (Chaplain) on Apr 07, 2001 at 00:36 UTC
    Ok, then riddle me this:

    #!/usr/local/bin/perl -l my @a = (1, 2, 3); my @b = (1, 2, 4); my @c = ( "equal", "a > b", "b > a" ); print ($c[@a<=>@b]); print ($c[@b<=>@a]); print ($c[(1, 2, 3)<=>(1, 2, 4)]); print ($c[(1, 2, 4)<=>(1, 2, 3)]);


    b > a
    a > b
    Something about the difference between an array and a list, I suspect - a distinction oft unclear in my mind, regardless of caffine levels.


      A LIST in SCALAR context returns its last item. An ARRAY in SCALAR context returns its count.

      A LIST in ARRAY/LIST context returns a LIST. An ARRAY in ARRAY/LIST context returns a LIST.

      That gets just about everyone at one time or another. It flat *BOGGLED* me for a while. Try this: perl -e 'print scalar( (1,2,3,4) ),$/'

      $you = new YOU;
      honk() if $you->love(perl)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://70577]
[erix]: Danewerk
[LanX]: I seem to remember that the danewall was build by the Frankish empire against the Danes
[erix]: 500 AD thru viking age
[erix]: that would make sense but wikipedia thinks otherwise
[LanX]: oh me was wrong ...
[erix]: but it always works both ways of course
[LanX]: Funny some weeks ago, I met people from the Cimbrian peninsula who didn't know it's called the Cimbrian peninsula ...
[LanX]: ... treid to make smalltalk and felt like Sheldon.
erix looks up Sheldon ...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2018-03-22 18:44 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (283 votes). Check out past polls.