Click here to get back home

How to pass a range (2 .. 42) by Getopt::Long to a script?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to pass a range (2 .. 42) by Getopt::Long to a script? Tom Brown 03-06-2008
Posted by Tom Brown on March 6, 2008, 6:38 pm
Please log in for more thread options
Hello.

The following range is "hardcoded" in a script.

for my $range ( 13 .. 20 ) {
...
}

Now, I would like pass the range dynamically as option (Getopt::Long)
to the script in order to avoid the changes in the script itself. What
is the appropriate solution?

Thanks in advance.

Tom



Posted by Joost Diepenmaat on March 6, 2008, 6:41 pm
Please log in for more thread options

> Now, I would like pass the range dynamically as option (Getopt::Long)
> to the script in order to avoid the changes in the script itself. What
> is the appropriate solution?

What did you try? The answer's pretty obvious:

# get $start and $end from Getopt::Long

for my $range ($start .. $end) {
# do stuff
}

note that this expects $end >= $start


--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Posted by Abigail on March 6, 2008, 10:55 pm
Please log in for more thread options
_
Tom Brown (not@home.net) wrote on VCCCI September MCMXCIII in
}} Hello.
}}
}} The following range is "hardcoded" in a script.
}}
}} for my $range ( 13 .. 20 ) {
}} ...
}} }
}}
}} Now, I would like pass the range dynamically as option (Getopt::Long)
}} to the script in order to avoid the changes in the script itself. What
}} is the appropriate solution?

Untested:

use Getopt::Long;

sub usage {
"usage: $0 --begin <begin> --end <end>\n";
}

GetOptions 'begin=i' => \my $begin,
'end=i' => \my $end
or die usage;

defined $begin or die usage;
defined $end or die usage;

for my $range ($begin .. $end) {
...
}

__END__



Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'

Similar ThreadsPosted
Version? Getopt::Long October 4, 2004, 3:00 pm
beginner trying to use Getopt::Long October 12, 2006, 2:58 pm
Getopt::Long install problems October 4, 2004, 6:33 pm
Option Values with Spaces using GetOpt::Long October 10, 2006, 2:30 am
Getopt::Long (how to make it die after saying "option requires an argument"?) June 13, 2005, 11:05 am
Parsing function args in Getopt::Long style January 11, 2008, 4:11 pm
Having problems parsing command line options using Getopt::Long on windows December 2, 2004, 8:48 am
How long is too long for cgi script? April 22, 2005, 12:07 pm
Script to pass info to GET string November 12, 2004, 8:59 am
Long running CGI script June 17, 2005, 4:13 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap