Hi, I have the following code to list the running PIDs on a Windows machine. It uses the Win32::API module.

#! /usr/bin/perl #use strict; use warnings; use Win32::API; #define some constants my $DWORD_SIZE = 4; my $PROC_ARRAY_SIZE = 300; my $MODULE_LIST_SIZE = 300; #define some Win32 API constants my $PROCESS_QUERY_INFORMATION = 0x0400; my $PROCESS_VM_READ = 0x0010; my $enum_proc = new Win32::API( 'psapi.dll', 'EnumProcesses', [P,N, +P], I ) || die "Cannot Enum Processes: $!\n"; #Create a Buffer Array my $proc_array = &MakeBuffer($DWORD_SIZE * $PROC_ARRAY_SIZE); my $proc_num = &MakeBuffer($DWORD_SIZE); if (0 != $enum_proc->Call($proc_array, $PROC_ARRAY_SIZE, $proc_num)) { $proc_num = unpack ("L", $proc_num) / $DWORD_SIZE; print "\$proc_num = $proc_num\n"; my @pid_lst = unpack("L$proc_num", $proc_array); foreach my $pid(@pid_lst) { print "$pid - Running\n"; } } sub MakeBuffer { my ($buffer_size) = @_; return("\x00" x $buffer_size); }
You will notice that use strict; is commented out. The reason is that when I uncomment use strict; I get the following error,
Bareword "P" not allowed while "strict subs" in use at C:\dev\Source_P +erl\MiscTests\pid\roth.pl line 17. Bareword "N" not allowed while "strict subs" in use at C:\dev\Source_P +erl\MiscTests\pid\roth.pl line 17. Bareword "P" not allowed while "strict subs" in use at C:\dev\Source_P +erl\MiscTests\pid\roth.pl line 17. Bareword "I" not allowed while "strict subs" in use at C:\dev\Source_P +erl\MiscTests\pid\roth.pl line 17. Execution of C:\dev\Source_Perl\MiscTests\pid\roth.pl aborted due to c +ompilation errors.
Any ideas how I can still use strict and line 17 together..? I got most of this code from Dave Roths Win32 Perl Scripting book.

-----
Of all the things I've lost in my life, its my mind I miss the most.

In reply to use strict and Win32::API by AcidHawk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.