Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Windows strawberry perl Getopt::Long fails

by Saved (Beadle)
on Dec 05, 2012 at 13:43 UTC ( [id://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"

Replies are listed 'Best First'.
Re: Windows strawberry perl Getopt::Long fails
by marto (Cardinal) 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 (Vicar) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found