Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to use getopts to look in a file and submit each item in the file to a job with different switches.

by mommydearest (Initiate)
on Mar 08, 2010 at 20:00 UTC ( #827422=perlquestion: print w/replies, xml ) Need Help??

mommydearest has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/local/bin/perl -w -s
#This script will allow the user to run a group of cells using a group file through the script.

$groupDir = &promptUser("Enter the entire directory path to your group file.");

print "$groupDir\n";

sub promptUser {
my($prompt, $default) = @_;
my $defaultValue = $default ? "$default" : "";
print "$prompt $defaultValue: ";
chomp(my $input = <STDIN>);
return $input ? $input : $default;
}

open(FH, "<$groupDir") || die "Sorry, I could not find a group file by that name here. $!\n";

use Getopt::Std;
my %Options;
getopt ('a', \%Options);

#this is the flow I want run on all of the cells in the file.
`$CLD_RV/rv_char.tcl`,

#it has 3 switches. The first is mandatory the last 2 are optional.
%Options = (c => `cell $cell`,
s => `use_slopefile 1`,
d => `dcc 1`)

close(FH);
  • Comment on How to use getopts to look in a file and submit each item in the file to a job with different switches.

Replies are listed 'Best First'.
Re: How to use getopts to look in a file and submit each item in the file to a job with different switches.
by ww (Archbishop) on Mar 08, 2010 at 21:09 UTC
Re: How to use getopts to look in a file and submit each item in the file to a job with different switches.
by cdarke (Prior) on Mar 09, 2010 at 09:16 UTC
    Aside from the comment above, you have a number of errors in you code:
    Please use strict;
    $CLD_RV is not created in the script. If this is an environment variable then use $ENV{'CLD_RV'}
    You use the wrong type of quotes for the values in %Options - use ' rather than `.
    Missing ; after the initialisation of %Options

    There are a few other nitpicks that I'll pass on.
      The OP sent me the following message:
      "hank you for your response. I know my code is a mess. What I am trying to find out is how to use Getopt effectively to run a script on a group file."

      First, if you know your code is a mess then then you are halfway there - the other half is to fix it. Perl::Tidy might be a start, and another is Perl::Critic.

      Please excuse my ignorance but I have no idea what a "group file" is, unless you mean /etc/group, which does not seem to fit your code. I asked Ms. Google and she came up with BZFlag (which I never heard of) and a search of CPAN gave BZFlag::Info. I have no idea if that is relevant, but you might like to follow that line of enquiry yourself.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://827422]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2019-12-16 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?