Pedro Antonio Reche wrote: > > Hi all, I using the code below that uses the Getopt::Std to process the > arguments from the command line (init subroutine). However, for some > reason I do not get the arguments from the switches. If anyone sees > what is the mistake I will be happy to hear about it. > > #!/usr/sbin/perl -w
use strict; > use Getopt::Std; > > &init; perldoc -q "What's the difference between calling a function as &foo and foo()" Found in /usr/lib/perl5/5.6.0/pod/perlfaq7.pod What's the difference between calling a function as &foo and foo()? > open(F, "$FILE") || die "I could not open $FILE\n"; ^ ^ perldoc -q quoting Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod What's wrong with always quoting "$vars"? You should include the $! variable in the error message so you know why open failed. > while(<F>){ > if (! /ATOM/) { > print $_; > } > else{ > if ( substr($_, $21,1) =~ $A ){ ^ ^^ That dollar sign shouldn't be there. You want to use 'eq' instead of '=~' to compare strings. > substr ($_, $21, 1, $B); > print $_; > } > else{ > print $_; > } > } You _always_ "print $_;" so why is used three times? substr $_, 21, 1, $B if /ATOM/ and substr $_, 21, 1 eq $A; print; > } > close(F); > > sub usage { > my $program = `basename $0`; use File::Basename; my $program = basename( $0 ); > chop($program); Why are you removing the last character from $program? > print STDERR " > $program [-p pdb ] [-a <chain_to_rename> ] [-b <new_chain_name>] [ > -h ] > > Rename chain id from pdb > > -p : pdb file > -a : chain to rename > -b : new chain name > > > "; > > } > sub init { > getopts('pab'); perldoc Getopt::Std SYNOPSIS use Getopt::Std; getopt('oDI'); # -o, -D & -I take arg. Sets opt_* as a side effect. ^^^^^^^^^^^^^^^^^^^^ getopt('oDI', \%opts); # -o, -D & -I take arg. Values in %opts ^^^^^^^^^^^^^^^^^^^^ getopts('oif:'); # -o & -i are boolean flags, -f takes an argument ^^^^^^^^^^^^^^^^^^^^ # Sets opt_* as a side effect. getopts('oif:', \%opts); # options as above. Values in %opts > if ($opt_p) { > $FILE = $opt_p; > print "$FILE\n"; > } else { > &usage; > exit; > } > if ($opt_a) { > $A = $opt_a; > chomp($A); Unless your shell or the user is doing something really weird there is no way that a command line option will have a terminating newline. > } > else { > &usage; > exit; > } > if ($opt_b) { > $B = $opt_b; > chomp($B); > } > else { > &usage; > exit; > } > } Why not just use $opt_p, $opt_a and $opt_b in the program? John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]