in reply to Re: Perl Module for dealing with number ranges
in thread Perl Module for dealing with number ranges

mmh. some year is passed, but.. I need to expand coordinate ranges, comma separated like in 4 4 , 5-7 5, 0 0, 0-23 2

With the help of moritz in the chat and plagiarizing rosetta code I ended with this:
#!perl use strict; use warnings; my $input = "@ARGV"; my @pairs = split /,/, $input; foreach my $pair (@pairs){ $pair =~ s/^\s+//;$pair =~ s/\s+$//; print map {"->$_\n"} &exp_coord($pair); } sub exp_coord { my ($r,$c)=split /\s/,"@_"; unless (defined $r and defined $c) {warn "Both must be defined. Re +ceived:",map{defined $_ ? "$_ " : 'UNDEF '}($r,$c);return} my @r; my @c; my @expanded; @r = $r=~/^(.*\d)-(.+)$/ ? ($1..$2) : ($r); @c = $c=~/^(.*\d)-(.+)$/ ? ($1..$2) : ($c); for my $rc (@r) { for my $cc (@c) { push @expanded, "$rc $cc" } }; return @expanded; }
HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.