in reply to Re^3: unpacking wmic command's unicode output
in thread unpacking wmic command's unicode output

You have:
my $searchfor = $#ARGV ? join(' ',@ARGV) : die("I need a process to lo +ok for.");

You want

my $searchfor = $#ARGV >= 0 ? join(' ',@ARGV) : die("I need a process +to look for.");

Or better yet:

my $searchfor = @ARGV ? join(' ',@ARGV) : die("I need a process to loo +k for.");

I don't understand why that's one one line. It doesn't save anything. I just adds complexity.

@ARGV or die("I need a process to look for."); my $searchfor = join(' ',@ARGV);

Replies are listed 'Best First'.
Re^5: unpacking wmic command's unicode output
by goibhniu (Hermit) on Nov 12, 2008 at 19:21 UTC

    What about the print $#ARGV; statement that printed 0 where you seem to have predicted it should print -1?

    I take your point about the difference between $#ARGV (highest index) and @ARGV in scalar context (number of elements) and agree I should have used the number of elements. That's a mental block for me and has caused me problems in the past.

    I also take your point about complexity. I think I was looking for something parallel in style to open() || die(); for consistency.


    #my sig used to say 'I humbly seek wisdom. '. Now it says:
    use strict;
    use warnings;
    I humbly seek wisdom.

      I ran your exact script and got the right result.

      >ARGVtest.pl $VAR1 = []; -1

      I think your system's handling of .pl files is broken.

      1. First, get the file type from the default key of HKEY_CLASSES_ROOT\.pl. For me, it's "Perl".
      2. Then, set the default key of HKEY_CLASSES_ROOT\Perl\shell\Open\command to "c:\perl\bin\perl.exe" "%1" %* (where "Perl" is the file type from the first step).

      As a .reg:

      Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.pl] @="Perl" [HKEY_CLASSES_ROOT\Perl] @="Perl File" [HKEY_CLASSES_ROOT\Perl\shell] [HKEY_CLASSES_ROOT\Perl\shell\Open] [HKEY_CLASSES_ROOT\Perl\shell\Open\command] @="\"c:\\perl\\bin\\perl.exe\" \"%1\" %*"

        Curiouser and curiouser . . .

        My HKCR\PerlScript\Shell\Open\Command is:
        C:\strawberry-perl\perl\bin\perl.exe "%1" "%*"

        I don't have HKEY_CLASSES_ROOT\Perl

        update: I took off the quotes around the %* and got your predicted results leaving me only with the $#ARGV vs. scalar(@ARGV) bug. THANKS and ++!


        #my sig used to say 'I humbly seek wisdom. '. Now it says:
        use strict;
        use warnings;
        I humbly seek wisdom.