Click here to get back home

Problems with GetOpt

 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
Problems with GetOpt Paul Richardson 05-17-2008
Get Chitika Premium
Posted by Paul Richardson on May 17, 2008, 12:38 pm
Please log in for more thread options
I am trying have following perl code:

#!/usr/bin/perl
#
# Options for this script
# -c : compile only don't simulate
# -gui: invoke simulator with the gui
#
use lib '/usr/lib/perl5/5.8.5/Getopt';
use Getopt::Long;
#
my $alternate_dot_vf_file = '';
#
GetOptions('f=s' => $alternate_dot_vf_file);
print "Printing vf file \n";
print $alternate_dot_vf_file;
die;

My expectation would have been that if I invoked this code "lets call
it hack" as follows:

hack --f someRandomFileName

I would have got print out that said:
Printing vf file
someRandonFileName

I am using the is my spefication to GetOptions incorrect ?

Thanks in advance



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
http://www.usenet.com

Posted by Dirk Heinrichs on May 17, 2008, 12:51 pm
Please log in for more thread options
Paul Richardson wrote:

> I am trying have following perl code:
>
> #!/usr/bin/perl
> #
> # Options for this script
> # -c : compile only don't simulate
> # -gui: invoke simulator with the gui
> #
> use lib '/usr/lib/perl5/5.8.5/Getopt';

What's this good for?

> use Getopt::Long;
> #
> my $alternate_dot_vf_file = '';
> #
> GetOptions('f=s' => $alternate_dot_vf_file);
> print "Printing vf file \n";
> print $alternate_dot_vf_file;

Looks good, except for missing '. "\n"' at the end of last line.

> die;

Why "die" when there is no error? Better "exit (0)".

> My expectation would have been that if I invoked this code "lets call
> it hack" as follows:
>
> hack --f someRandomFileName
>
> I would have got print out that said:
> Printing vf file
> someRandonFileName

And what do you get?

> I am using the is my spefication to GetOptions incorrect ?

Yes.

Bye...

Dirk

Posted by Paul Richardson on May 18, 2008, 5:56 pm
Please log in for more thread options

> Paul Richardson wrote:
>
>> I am trying have following perl code:
>>
>> #!/usr/bin/perl
>> #
>> # Options for this script
>> # -c : compile only don't simulate
>> # -gui: invoke simulator with the gui
>> #
>> use lib '/usr/lib/perl5/5.8.5/Getopt';
>
> What's this good for?
For some reason my path for searching was set up correctly
>
>> use Getopt::Long;
>> #
>> my $alternate_dot_vf_file = '';
>> #
>> GetOptions('f=s' => $alternate_dot_vf_file);
>> print "Printing vf file \n";
>> print $alternate_dot_vf_file;
>
> Looks good, except for missing '. "\n"' at the end of last line.
ok
>
>> die;
>
> Why "die" when there is no error? Better "exit (0)".
ok
>
>> My expectation would have been that if I invoked this code "lets call
>> it hack" as follows:
>>
>> hack --f someRandomFileName
>>
>> I would have got print out that said:
>> Printing vf file
>> someRandonFileName
>
> And what do you get?
I got n nothing as in , nothing was printed out , I expected to see
"someRandomFileName" printed out

>
>> I am using the is my spefication to GetOptions incorrect ?
>
> Yes.
>
> Bye...
>
> Dirk



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
http://www.usenet.com

Posted by Dirk Heinrichs on May 19, 2008, 12:25 pm
Please log in for more thread options
Paul Richardson wrote:

>> And what do you get?
> I got n nothing as in , nothing was printed out , I expected to see
> "someRandomFileName" printed out

Add the \n to the second print, like

print $someRandomFileName . "\n";

and replace "die" with "exit (0)". Should work, then.

Bye...

Dirk

Posted by Ben Morrow on May 19, 2008, 2:11 pm
Please log in for more thread options

> Paul Richardson wrote:
>
> >> And what do you get?
> > I got n nothing as in , nothing was printed out , I expected to see
> > "someRandomFileName" printed out
>
> Add the \n to the second print, like
>
> print $someRandomFileName . "\n";

print "$someRandomFileName\n";

or

local $\ = "\n";
print $someRandomFileName;

or

use 5.010;

say $someRandomFileName;

> and replace "die" with "exit (0)". Should work, then.

s/and/or/;

Or just fall off the end, as is usual with Perl programs.

Ben

--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *

Similar ThreadsPosted
Getopt::Long install problems October 4, 2004, 6:33 pm
Having problems parsing command line options using Getopt::Long on windows December 2, 2004, 8:48 am
Is this bug in Getopt::Std? October 20, 2006, 3:00 pm
Version? Getopt::Long October 4, 2004, 3:00 pm
Getopt::Std , option with no argument December 27, 2005, 7:52 am
beginner trying to use Getopt::Long October 12, 2006, 2:58 pm
Any one merged the httpd QUERYSTRING with getopt() ? November 22, 2004, 4:56 pm
Getopt::Std argument list mistake? August 20, 2006, 7:41 am
Option Values with Spaces using GetOpt::Long October 10, 2006, 2:30 am
How to pass a range (2 .. 42) by Getopt::Long to a script? March 6, 2008, 6:38 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap