Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Windows strawberry perl Getopt::Long fails

by Saved (Beadle)
on Dec 05, 2012 at 13:43 UTC ( #1007291=perlquestion: print w/ replies, xml ) Need Help??
Saved has asked for the wisdom of the Perl Monks concerning the following question:

Windows strawberry perl Getopt::Long fails although indentical to that run on Linux. Is there a fix/workarround?
use Getopt::Long; GetOptions ('library=s' => \@libfiles); @libfiles = split(/,/,join(',',@libfiles)); print "@libfiles\n"; $LstCnt=@libfiles; print "$LstCnt\n";
prints "0"

Comment on Windows strawberry perl Getopt::Long fails
Download Code
Replies are listed 'Best First'.
Re: Windows strawberry perl Getopt::Long fails
by marto (Bishop) on Dec 05, 2012 at 14:05 UTC

    Did you run it properly? Windows XP, Strawberry Perl 5.12:

    C:\>perl opt.pl --library=foo foo 1
Re: Windows strawberry perl Getopt::Long fails
by 2teez (Priest) on Dec 05, 2012 at 14:52 UTC

    Hi Saved,
    Apparently, you didn't pass any argument to your script from the Command Line Interface (CLI), when running it.
    So, your variable @libfiles is empty, thus, when pass to a scalar variable you get the output "0", when printed.
    Consider this:

    use warnings; use strict; use Data::Printer; my @gn; p @gn; # print [] i.e empty print my $c = () = @gn; ## print 0

    So to get the desired result, do this from your CLI:perl script.pl --library=foo,bar,baz then press <ENTER> key.
    using the following as your perl script.
    # your script.pl use warnings; use strict; use Getopt::Long; my @libfiles; GetOptions( 'library=s' => \@libfiles ); @libfiles = split( /,/, join( ',', @libfiles ) ); print "@libfiles\n"; my $LstCnt = @libfiles; print "$LstCnt\n";
    Output
    foo bar baz 3
    So, Getopt::Long is not broken after all.
    ++ martoz.
    Hope this helps

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
      Found using the #!C:\strawberry\perl\bin\perl.exe first line and running "MLnch.pl -l prd,ift" fails,but no error. But adding the path to %PATH% , and using: perl MLnch.pl -l prd,ift works.

        #!C:\strawberry\perl\bin\perl.exe first line and running "MLnch.pl -l prd,ift" fails,but no error..
        You probably want to read perlrun and #! and quoting on non-Unix systems especially.
        You might as well still use #!/usr/bin/perl on window OS. It works for me.

        If you tell me, I'll forget.
        If you show me, I'll remember.
        if you involve me, I'll understand.
        --- Author unknown to me

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-07-31 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls