Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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
Re: Windows strawberry perl Getopt::Long fails
by marto (Chancellor) 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 scrutinizing the Monastery: (4)
As of 2014-07-24 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (157 votes), past polls