Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: How to compare arrays? (xmms alarm clock)

by ginseng (Pilgrim)
on Jun 29, 2001 at 08:05 UTC ( [id://92530]=note: print w/replies, xml ) Need Help??


in reply to Re: How to compare arrays? (xmms alarm clock)
in thread How to compare arrays? (xmms alarm clock)

my mistake. i tried to implement your idea, and did it wrong. i thought it should have worked and didn't try hard enough. upon further effort it worked exactly as advertised. it even looks clean and understandable. i just wish it were more intuitive to begin with...

revised...

do { my @timenow = localtime(time); @current = ($timenow[2], $timenow[1]); sleep 5; } until ("@wake" eq "@current");

so can i be greedy and ask for more ways to compare the two?

Replies are listed 'Best First'.
Re:{3} How to compare arrays? (xmms alarm clock)
by jeroenes (Priest) on Jun 29, 2001 at 10:14 UTC
    See How to test equality of hashes? for more ways.

    You can leave out the @timenow:

    @current = (localtime time)[1..2];
    ...just gives you the slice.

    Hope this helps,

    Jeroen

    Update: You're welcome. That prob is easily solved with reverse:

    @current = reverse (localtime time)[1..2];

      This leaves @current with a different array order than @wake has. split /:/ leaves $wake[0] with the hour, and $wake[1] with the minute. localtime[1..2] would return the minute then the hour. to do the comparison, i'd have to invert one array.

      thank you for the hashes link. i'm glad i didn't find it before posting this question. it makes this question look way too easy. as you can see, i've got one solution that works, "@array1" eq "@array2", but it still seems like there'd be a simpler (rather, more intuitive) way. But perhaps my intuition is just not on yet, with Perl.

Re: Re: Re: How to compare arrays? (xmms alarm clock)
by davorg (Chancellor) on Jun 29, 2001 at 12:50 UTC
andye Re cubed: How to compare arrays? (xmms alarm clock)
by andye (Curate) on Jun 29, 2001 at 13:00 UTC
    How about something like...
    until ((grep {$wake[$_] == $current[$_]} (0..$#wake)) == @wake));

    (NB can't check this right now though)

    andy.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-19 04:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found