Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Validate array of numbers in sequence

by Corion (Patriarch)
on Sep 08, 2003 at 11:01 UTC ( [id://289738]=note: print w/replies, xml ) Need Help??


in reply to Re: Validate array of numbers in sequence
in thread Validate array of numbers in sequence

Both, your and Abigail-IIs solution will fail for duplicate elements (although I don't know whether that's a problem or not) :

#!/usr/bin/perl use strict; use warnings; my @list = qw( 1 1 2 ); my %hash; @hash{@list}=1; delete $hash{$_} for (1..@list); print "is sequence\n" unless %hash;
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Replies are listed 'Best First'.
Re: Validate array of numbers in sequence
by cLive ;-) (Prior) on Sep 08, 2003 at 11:21 UTC
    Fair point. Just switch things around a little...
    my %hash; @hash{1..@list}=1; delete $hash{$_} for (@list);

    Funny, this was how I did it originally, but I thought the other way round looked prettier :)

    cLive ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found