Just for the sake of showing another way to do it...
 
########################

my $input = "2-8,9,11,18-21";

$input =~ s/-/\.\./g;

print join(',',eval($input));

########################

or if you don't want to print out the list but iterate through it...

########################

my $input = "2-8,9,11,18-21";

$input =~ s/-/\.\./g;

foreach(eval($input)){

     ...do something

}

#########################

        -----Original Message----- 
        From: John W. Krahn [mailto:[EMAIL PROTECTED] 
        Sent: Tue 8/31/2004 11:31 PM 
        To: Perl Beginners 
        Cc: 
        Subject: Re: A simple way? A Perl way?
        
        

        <snip>

        > I am looking for a simple Perl way to decode the following, which can be any
        > grouping of number
        >
        >    2-8,9,11,18-21
        >
        > Into
        >    2,3,4,5,6,7,8,9,11,18,19,20,21
        
        $ perl -le' print join ",", map /(\d+)-(\d+)/ ? $1 .. $2 : $_, split /,/,
        "2-8,9,11,18-21"'
        2,3,4,5,6,7,8,9,11,18,19,20,21
        

Reply via email to