harishnuti has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl print "To get the range of numbers \n"; print "Enter the range to see expansion \n"; chomp($range=<STDIN>); print "The range from subroutine is :",join("==>",&get_numbers_from_ra +nges($range)),"\n"; sub get_numbers_from_ranges { my $spec = shift; my %numbers; foreach my $x ( split ',', $spec ) { $x =~ s/\s*//g; if ( $x =~ /(\d+)-(\d+)/ ) { $numbers{$_} = undef for $1 .. $2; } else { $numbers{$x} = undef; } } # subtracting every element by one because these are used in array +s i.e. 1st element in array index is 0 #return map { $_ - 1 } sort { $a <=> $b } keys %numbers; return map { $_ - 1 } keys %numbers; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting Ranges from Sequences using hashes
by GrandFather (Saint) on Sep 25, 2008 at 04:11 UTC | |
by harishnuti (Beadle) on Sep 26, 2008 at 02:12 UTC | |
|
Re: Extracting Ranges from Sequences using hashes
by jwkrahn (Abbot) on Sep 25, 2008 at 04:34 UTC | |
|
Re: Extracting Ranges from Sequences using hashes
by andreas1234567 (Vicar) on Sep 25, 2008 at 11:30 UTC | |
|
Re: Extracting Ranges from Sequences using hashes
by johngg (Canon) on Sep 25, 2008 at 10:00 UTC | |
|
Re: Extracting Ranges from Sequences using hashes
by parv (Parson) on Sep 25, 2008 at 04:22 UTC |