Hello, While learning perl., i had a example to do with getopt : my sample program is : http://rapidshare.com/files/47947512/getopt.pl i have came across with the below error : Kindly, someone help me to get thru this error if you know !
I'm no perl expert but i would imagine you need a space between the print and the quotes on line 10 of your perl script.
I have uploaded here. Once you download it, change the extension to .pl from .txt ! hope that will help you as well as me ! Regards !
ok, i made two changes to make it work on my server... I changed the mixed case "If" to "if" on line 9 and added curly brackets after the condition. try this instead... se Getopt::Std; getopts (":S:n:",\%args); if (defined $args{s}){ $string = $args{s}; } if (defined $args{n}) { $number = $args{n}; } if (!defined $args{s} or !defined $args{n}){ print "Usage: Perl $0 -s String -n Number/n"; exit; } print "this is a string = $string this is a Number = $number/n"; Code (markup): Now, I still get an error which says... Can't locate object method "se" via package "Getopt::Std" (perhaps you forgot to load "Getopt::Std"?) at ./getopt.pl line 1. But I'm assuming you've got something configured I haven't.
of course if you want to use less memory by eliminating the variables and speed it up by eliminating the extra conditionals (if) use Getopt::Std; getopts (":S:n:",\%args); if (defined $args{s} && defined $args{n}){ print "this is a string = $args{s} this is a Number = $args{n}/n"; } else { print "Usage: Perl $0 -s String -n Number/n"; exit; } Code (markup):
lol. This is an easy fix. at the end of the print statements you have /n"; You need to replace it with \n"; Notice the difference in the slashes. If you don't know how to type the correct slash it is SHIFT+BUTTON ABOVE ENTER