Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2:dealing with coordinate ranges

by Discipulus (Canon)
on May 20, 2014 at 11:27 UTC ( [id://1086777]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-03-28 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found