Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

(jeffa) Re: (with Getopt::Declare)

by jeffa (Bishop)
on Mar 30, 2002 at 20:38 UTC ( #155482=note: print w/replies, xml ) Need Help??

in reply to

Regarding Option parsing modules - this is not to bug you into using them, but rather an option for others to decide.

I though to myself, "hmmmm ... let's use TheDamian's Getopt::Declare" and proceded to RTFM. I had always wanted to learn this module, and now seemed like the time.

After about 40 minutes of racking my brain (:D) i finally came up with this:

#!/usr/bin/perl -w use strict; use LWP::UserAgent; use Getopt::Declare; # -h, -v, --help, --version are included # and these are tabs - not spaces! my $spec = q( -a List all matches --all [ditto] ); my $args = Getopt::Declare->new($spec); my $all = $args->{'--all'} || $args->{'-a'}; for my $woord ($args->unused) { # insert for loop block innards from code above }
But that is 40 minutes of well spent time, because now i see the power of this module. And thanks to the Von Neumann bottleneck of having to retrieve the page from the Internet, the fact that Getopt::Declare is slower than the option parsing code above is negligible.

P.S. i also have no quandaries about using regexes to parse HTML, just as long as the coder understands how to use the CPAN HTML parsers. Sometimes using regexes really is easier. Sometimes.


(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: (with Getopt::Declare)
by danger (Priest) on Mar 30, 2002 at 21:51 UTC

    In the interest of tmtowtdi, here's an alternate Getopt::Declare scenario that sets up the $all and @words variables in action blocks. Here I decided to make the search words required (but without option description), and just allow for -a as an abbrev. of -all (instead of using the --all version):

    #!/usr/bin/perl -w use strict; use LWP::UserAgent; use Getopt::Declare; use vars qw/$all @words/; my $opts = Getopt::Declare->new(<<'EOS'); -a[ll] List all matches {$all = 1} <terms:s>... [required] {@words = @terms} EOS for my $word (@words) { # insert fetch code ... # ... last unless $all; } __END__

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://155482]
[marto]: good morning all
[Corion]: Hi marto!
[marto]: Hey Corion, how are things?

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-05-24 07:20 GMT
Find Nodes?
    Voting Booth?