Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Windows strawberry perl Getopt::Long fails

by 2teez (Priest)
on Dec 05, 2012 at 14:52 UTC ( #1007301=note: print w/ replies, xml ) Need Help??


in reply to Windows strawberry perl Getopt::Long fails

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


Comment on Re: Windows strawberry perl Getopt::Long fails
Select or Download Code
Re^2: Windows strawberry perl Getopt::Long fails
by Saved (Beadle) on Dec 05, 2012 at 18:12 UTC
    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
        Works, but could I eliminate the "perl \strawberry\c\bin\":
        C:\>perl \strawberry\c\bin\MLnch3.pl -l diebelr -s dynprod,aimprod
        Getopt fails:
        C:\>MLnch3.pl -l diebelr -s dynprod,aimprod XX 0 YY 0 Use of uninitialized value $LGN in concatenation (.) or string at C:\s +trawberry\ c\bin\MLnch3.pl line 43, <DATA> line 101. Use of uninitialized value $LGN in concatenation (.) or string at C:\s +trawberry\ c\bin\MLnch3.pl line 47, <DATA> line 101.
        Can't find script:
        C:\>perl MLnch3.pl -l diebelr -s dynprod,aimprod Can't open perl script "MLnch3.pl": No such file or directory
        @INC & path:
        C:\>perl -e "print @INC;" <code> C:/strawberry/perl/site/libC:/strawberry/perl/vendor/libC:/strawberry/ +perl/lib. C:\>path PATH=C:\winnt\system32;C:\winnt;C:\winnt\system32\WBEM;C:\Program File +s\Personal Communications;C:\DST\AWDView\BIN;C:\DST\AWDView\DLL;c:\dst\bin;c:\ds +t\awdwin\b in;C:\DST\EnCorr\BIN;c:\dst\bin;C:\Program Files\Support Tools\;C:\Pro +gram Files \Sybase\Adaptive Server Anywhere 6.0\win32;C:\DST\ICU;C:\Program Files +\ATI Techn ologies\ATI Control Panel;C:\PROGRA~1\CA\SHARED~1\SCANEN~1;C:\Program +Files\CA\S haredComponents\ScanEngine;C:\Program Files\Hitec Laboratories\Shared\ +APDFL\Bin; C:\Notes;C:\Program Files\Utimaco\SafeGuard Easy\;C:\PROGRA~1\IBM\CLIE +NT~1;C:\PR OGRA~1\IBM\CLIENT~1\Shared;C:\Program Files\putty;C:\strawberry\c\bin; +C:\strawbe rry\perl\site\bin;C:\strawberry\perl\bin;C:\winnt\system32\WindowsPowe +rShell\v1. 0;C:\DST\BIN
        The script minus the DATA section:
        #!/usr/bin/perl #!C:\strawbery\perl\bin\perl.exe #<MLnch.pl> Run a command or program on a group of Systems use strict; use warnings; use File::Basename; use Getopt::Long; qw(); my ($SysGroup, $HFILE, $SYS, @libfiles, @finfo, @DataList, @SysLst, @P +arts, @Systems, @LIST, $LstCnt, $LINE, $truth, $sys, @list, $list, @c +olumns, $LOGIN, $Sup, $LGN, $GRP, @systems, $GrpCnt, @group, $SysCnt, + $grp, @Fields); GetOptions ("systems=s" => \$SYS , "login=s" => \$LGN , "group=s" => \ +$GRP ); @group = split(/,/, $GRP) if($GRP); @systems = split(/,/, $SYS) if($SYS); $GrpCnt=@group; $SysCnt=@systems; print "@list XX $GrpCnt YY $SysCnt\n"; @DataList = grep !/^\x23/, <DATA>; $truth=0; foreach $LINE (@DataList) { @Fields=split(/:/, $LINE); if($GRP) { foreach $grp (@group) { if ( "$LINE" =~ /:$grp:/){ $truth++; } } if ( $truth == $GrpCnt ) { push(@SysLst, $Fields[1]); } $truth=0; } elsif ($SYS) { foreach $sys (@systems) { if ( "$LINE" =~ /:$sys:/){ push (@SysLst, $Fields[1]); } } } } print "@SysLst\n"; print "$LGN\n"; my $cmd="start kitty.exe"; #my $args=" -l $LGN -agent -i \"C:\Program Files\PuTTY\MyKeys\RsaKey.p +pk\" -load "; my $args=" -l $LGN -load "; sub run_in_bg; $Sup="i"; foreach my $System (@SysLst) { print "$System\n"; run_in_bg "$cmd $args $System$Sup"; } sub run_in_bg { my $pid = fork; die "Can't fork a new process" unless defined $pid; # child gets PID 0 if ($pid == 0) { exec(@_) || die "Can't exec $_[0]"; } # in case you wanted to use waitpid on it #return $pid; } __DATA__ a list of systems...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007301]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2015-07-04 10:17 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 (59 votes), past polls