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 ;-)