Re: stop a Windows application from within a Perl script
Jack D. wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dan Jablonsky Sent: April 17, 2006 8:00 PM To: perl-win32-users@listserv.ActiveState.com Subject: stop a Windows application from within a Perl script Hi all, I have a very simple script that pings the outside world and reboots a router when it gets no answer to the ping anymore; on top of that I need to stop and start again a windows application. I know how to start the app and I know how to stop it if it were unix -> to stop the app, just kill the associated process ... How does one do this in Windows? If you start the application using Win32::Process you would just kill it using the pid (similar to unix) Win32::Process::KillProcess($pid) But better would be to get the window handle and send a WM_CLOSE message to it. regards, Reinhard ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: stop a Windows application from within a Perl script
There's also a great command line tool by Mark Russinovich (which is easy to launch from a perl script) called pskill (you can get it at www.sysinternals.com). -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jack D. Sent: Monday, April 17, 2006 10:52 PM To: 'Dan Jablonsky'; perl-win32-users@listserv.ActiveState.com Subject: RE: stop a Windows application from within a Perl script > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Dan Jablonsky > Sent: April 17, 2006 8:00 PM > To: perl-win32-users@listserv.ActiveState.com > Subject: stop a Windows application from within a Perl script > > Hi all, > I have a very simple script that pings the outside world and > reboots a router when it gets no answer to the ping anymore; > on top of that I need to stop and start again a windows application. > I know how to start the app and I know how to stop it if it > were unix -> to stop the app, just kill the associated process ... > How does one do this in Windows? If you start the application using Win32::Process you would just kill it using the pid (similar to unix) Win32::Process::KillProcess($pid) J. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Working together. For life.(sm) _ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk - Portuguese - Svenska: www.cardinalhealth.com/legal/email ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Fw: Non-blocking IO?
I'd look at POE which contains functionality to do lots of things "non-blocking" including Web server functionality -- see poe.perl.org. Look at the cookbook examples under "Web" at http://poe.perl.org/?POE_Cookbook And there's a POE mailing list at [EMAIL PROTECTED] For Win32 PPMs, you'll need to get the latest version of POE 0.34 from Randy Kobes' PPM repository. The ActiveState repository has a problem with POE (or POE has a problem with the ActiveState Repository) because the ActiveState repository uses 5.8.0 (~3 years old) to build PPMs from the CPAN distributions. See: http://theoryx5.uwinnipeg.ca/ppms/ Regards, ... Dewey > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of > Lyle Kopnicky > Sent: Tuesday, April 18, 2006 12:22 AM > To: Perl-Win32-Users@listserv.ActiveState.com > Subject: Non-blocking IO? > > > Hi folks, > > I'm using the HTTP::Daemon module. Is there any way to do non-blocking > IO with that? Thanks. > > -- > Lyle Kopnicky > Software Project Engineer > Veicon Technology, Inc. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: stop a Windows application from within a Perl script
On XP (and I think on 2000) there are standard command-line tools for this; 'tasklist' will list all the processes, and 'taskkill' will kill a specified one. Both are normally installed in c:\windows\system32 Dan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of LeFevre, Ken Sent: Tuesday, April 18, 2006 7:31 AM To: Jack D.; Dan Jablonsky; perl-win32-users@listserv.ActiveState.com Subject: RE: stop a Windows application from within a Perl script There's also a great command line tool by Mark Russinovich (which is easy to launch from a perl script) called pskill (you can get it at www.sysinternals.com). -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jack D. Sent: Monday, April 17, 2006 10:52 PM To: 'Dan Jablonsky'; perl-win32-users@listserv.ActiveState.com Subject: RE: stop a Windows application from within a Perl script > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Dan Jablonsky > Sent: April 17, 2006 8:00 PM > To: perl-win32-users@listserv.ActiveState.com > Subject: stop a Windows application from within a Perl script > > Hi all, > I have a very simple script that pings the outside world and > reboots a router when it gets no answer to the ping anymore; > on top of that I need to stop and start again a windows application. > I know how to start the app and I know how to stop it if it > were unix -> to stop the app, just kill the associated process ... > How does one do this in Windows? If you start the application using Win32::Process you would just kill it using the pid (similar to unix) Win32::Process::KillProcess($pid) J. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Working together. For life.(sm) _ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk - Portuguese - Svenska: www.cardinalhealth.com/legal/email ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs -- The information contained in this communication and any attachments is confidential and may be privileged, and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. ASML is neither liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Quick Q [-d test with unicode/wide directory names]
And for what it's worth, I submitted this "solution" using the Win32 API calls FindFirstFileW, FindNextFileW in late January: http://aspn.activestate.com/ASPN/Mail/Message/2996684 More generally, the built-in directory and file operators don't work with directory and filenames that contain unicode characters, there's nothing in the Win32 Perl documentation that warns about this limitation, it's easy to burn lots of time trying to figure out why a script that should work, that's been working, doesn't work (ok, at least it was easy for me to burn lots of time on this...), the Win32API::File module doesn't include this functionality (though it would seem to be the right place for it), I've seen nothing on the Perl5 porters list or anywhere else that indicates whether this limitation will ever be fixed, ... One of these days I need to write a Perl module / CPAN distribution to do this Regards, ... Dewey "Timothy Johnson" <[EMAIL PROTECTED]> 04/17/2006 08:38 PM To D D Allen/Fairfax/[EMAIL PROTECTED], "Ng, Bill" <[EMAIL PROTECTED]>, "Trevor Joerges" <[EMAIL PROTECTED]> cc Subject RE: Quick Q [-d test with unicode/wide directory names] If you follow the links inside the link you just posted, you’ll eventually come to this: http://groups.google.com/group/perl.unicode/browse_thread/thread/21b8a3cde8e54b8f/86ab5af239975df7?#86ab5af239975df7 Peter Gordon wrote: > Hi Guys. > I need some help with a project that I have. I have to copy files using > Perl to different places and the filenames may be in Hebrew, Chinese, > Korean etc. > The problem is, that filenames, when using opendir, are returned as > question marks. In the DOS box I have set the codepage to 862. So DIR > returns accented characters, but Perl still returns question marks. I > have also set "use utf8", but that didn't help either. > So the problem I have is how to proceed. Should I give up with Perl and > use Java or C? Any suggestions gratefully received. I don't think you have to give up using Perl. Something like this should work: #!/usr/bin/perl use strict; use warnings; use Encode; use IO::Dir; # Let perl know that we want to output cp862 on STDOUT binmode( STDOUT, ':encoding(cp862)' ); my $dir = IO::Dir->new('.') or die("Failed to open dir : $!"); while ( my $entry = $dir->read ) { next if $entry =~ /^\.{1,2}$/; # Decode octets into perl's internal unicode encoding $entry = Encode::decode_utf8($entry, 1); printf( "%s\n", $entry ); } $dir->close; Regards Christian From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of D D Allen Sent: Monday, April 17, 2006 2:05 PM To: Ng, Bill; Trevor Joerges Cc: perl-win32-users@listserv.ActiveState.com Subject: Re: Quick Q [-d test with unicode/wide directory names] A quick word of caution about the -d directory operator under Win32 (and -e and opendir and ...). If the Win32 directory name contains unicode / wide characters, the -d operator will always return "false". As I understand it, Win32 Perl uses the A (ansi) version of the Win32 API directory calls -- which don't work with file and directory names that include unicode characters. So even if you pass "-d" a string variable in Windows native UTF16LE format that correctly matches the directory name (with unicode characters) on disk, if will return "false". Same goes for the "-e" file existence test -- for filenames that contain unicode characters. "opendir" suffers from the same problem. Apparentlly, there was a "USING_WIDE" macro / switch in the Perl source that attempted to deal with Win32 file and directory names that contain unicode characters (that would make Perl use the Win32 API "W" version directory calls) but it was disabled with Perl 5.8. See: http://aspn.activestate.com/ASPN/Mail/Message/perl5-porters/2933666 [Yes, there are workarounds to this problem... all of which involve not using Perl's built-in directory functions.] ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
exhausting file handles in Win32
Hello! I am new perl (again). I am performing QA on software developed at my company. My task is to try to exhaust all file handles on the Win32 platform (Win2K and WinXP) and see how our software behaves. With the code below, I am able to open no more than 2045 file handles under a cmd.exe shell and 3197 under a Cygwin shell. Regards, Carlos #!/usr/bin/perl -w if([EMAIL PROTECTED]) { print "usage: filehandles \n"; exit; } $totalfhs = shift; #I could use $ARGV[0]; $i = 1; while ($i == $totalfhs || $i < $totalfhs) { open $ar[$i], ">_$i.tmp" or die "Could not open $i"; $i++; } print $i-1 ." filehandles are open, hit any key to close \n"; $_ = ; $i--; #cheesy but it is what is needed here while ($i > 0) { close($ar[$i]) or die "\n\nError closing: $!"; unlink("_$i.tmp") or die "\n\nError deleting: $!"; $i--; } ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: breaking out of a for/foreach loop...
Bruce, You can use a "Label" and a "goto" statement. for (@array) { if (condition met) { goto Label; } } LABEL: ... Hope this helps. Dave Kazatsky Senior Middleware Engineer NSE - Solutions Engineering W. (732) 893-4351 C. (973) 865-8106 ">"bruce" <[EMAIL PROTECTED]> "bruce" <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 04/17/2006 10:00 PM Please respond to bedouglas To: perl-win32-users@listserv.ActiveState.com cc: Subject: breaking out of a for/foreach loop... ok.. i'm embarassed.. how does one break out of a for/foreach loop?? i thought it was exit/break... pointers? thanks -bruce ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs The information contained in this message may be CONFIDENTIAL and is for the intended addressee only. Any unauthorized use, dissemination of the information, or copying of this message is prohibited. If you are not the intended addressee, please notify the sender immediately and delete this message. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Re: breaking out of a for/foreach loop...
Its "last" what you are looking for. This will break out of the inner-most loop. Optionally, you can put a label at the start of your loop and exit it by name, like: my $foo = 0; OUTER: while (1) { INNER: while (1) { $foo++; if ($foo > 1) last INNER; } } The "last INNER" will exit the inner loop. If it were "last OUTER" it would exit both of them immediately. This is the same thing as executing a GOTO statement to a label outside the loops, but it seems cleaner in the code. -dZ. - Original Message - From: [EMAIL PROTECTED] Sent: 4/18/2006 9:58:15 AM To: [EMAIL PROTECTED] Cc: perl-win32-users@listserv.ActiveState.com;[EMAIL PROTECTED] Subject: Re: breaking out of a for/foreach loop... > > Bruce, > > You can use a "Label" and a "goto" statement. > > > for (@array) > { > if (condition met) > { > goto Label; > } > } > > LABEL: > ... > > Hope this helps. > > Dave Kazatsky > Senior Middleware Engineer > NSE - Solutions Engineering > W. (732) 893-4351 > C. (973) 865-8106 > > > |-+-> > | | "bruce" <[EMAIL PROTECTED]> | > | | Sent by: | > | | [EMAIL PROTECTED]| > | | veState.com | > | | | > | | | > | | 04/17/2006 10:00 PM | > | | Please respond to bedouglas | > | | | > |-+-> > > >| > | > | > | To: perl-win32-users@listserv.ActiveState.com > | > | cc: > | > | Subject: breaking out of a for/foreach loop... > | > > >| > > > > > > ok.. > > i'm embarassed.. how does one break out of a for/foreach loop?? > > i thought it was exit/break... > > pointers? > > thanks > > -bruce > > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > > > The information contained in this message may be CONFIDENTIAL and is for the > intended addressee only. Any unauthorized use, dissemination of the > information, or copying of this message is prohibited. If you are not the > intended addressee, please notify the sender immediately and delete this > message. > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: exhausting file handles in Win32
OK, I thought perhaps using the FileHandle module would help, I rewrote the script in the fashion below. And it remains limited to 3197 using the Cygwin shell or 2045 using cmd.exe. I _assume_ the issue is something to do with perl being an interpreted language and an environment variable?? Is there a method to get this script to open say 250,000 file handles (or whatever is the theoretical limit of file handles in Win32). As one can guess, I am limited in my programming experience, thus I don't know if I am barking up the wrong tree. Perhaps a compiled language should be used for this task Help, please... #!/usr/bin/perl -w use strict; use FileHandle; if([EMAIL PROTECTED]) { print "usage: filehandles \n"; print "usage: is the file extension to \n"; print "usage: use when creating files. \n"; print "example: filehandles 3197 tmp1"; exit; } my $numFh = $ARGV[0]; my $fhExt = $ARGV[1] || '_tmp'; chomp($numFh); if ($numFh =~ m/[^0-9]/) { print "Impossible! Usage: filehandles \n"; print "\"$numFh\" is not an integer!! exiting...\n"; exit; } $numFh++; # we have to add one because of the way I wrote the loop my $fhLoop = 1; #start at one for readability my @fileDb; while ($fhLoop < $numFh) { #print "Opening filehandle $fhLoop\n"; #do we really need to print it all? $fileDb[$fhLoop] = new FileHandle "$fhLoop.$fhExt", "w" or die "\n\nError: $!"; $fhLoop++; } $fhLoop--; # back it up one, cause the extra wasn't really created. print "Created $fhLoop filehandle(s) hit any key to quit.\n"; my $waitforkeystroke = ; while ($fhLoop > 0) { close($fileDb[$fhLoop]) && unlink("$fhLoop.$fhExt") or die "\n\nError removing: $!\n"; $fhLoop--; } cabz wrote: Hello! I am new (to) perl. I am performing QA on software developed at my company. My task is to try to exhaust all file handles on the Win32 platform (Win2K and WinXP) and see how our software behaves. With the code below, I am able to open no more than 2045 file handles under a cmd.exe shell and 3197 under a Cygwin shell. Regards, Carlos #!/usr/bin/perl -w if([EMAIL PROTECTED]) { print "usage: filehandles \n"; exit; } $totalfhs = shift; #I could use $ARGV[0]; $i = 1; while ($i == $totalfhs || $i < $totalfhs) { open $ar[$i], ">_$i.tmp" or die "Could not open $i"; $i++; } print $i-1 ." filehandles are open, hit any key to close \n"; $_ = ; $i--; #cheesy but it is what is needed here while ($i > 0) { close($ar[$i]) or die "\n\nError closing: $!"; unlink("_$i.tmp") or die "\n\nError deleting: $!"; $i--; } ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
running a perl app
hi.. using linux. when i do "perl foo.pl" everything works ok. when i do "./foo.pl" i get errors.. i've set the exe bit "chmod 775 foo.pl"... any idea as to what's going on... thanks -bruce ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: exhausting file handles in Win32
On Tue, 18 Apr 2006, Carlos Barbet wrote: > OK, I thought perhaps using the FileHandle module would help, I > rewrote the script in the fashion below. And it remains limited to > 3197 using the Cygwin shell or 2045 using cmd.exe. I _assume_ the > issue is something to do with perl being an interpreted language and > an environment variable?? Is there a method to get this script to open > say 250,000 file handles (or whatever is the theoretical limit of file > handles in Win32). As one can guess, I am limited in my programming > experience, thus I don't know if I am barking up the wrong tree. > Perhaps a compiled language should be used for this task You are doing something wrong if you need so many filehandles open simultaneously. In standard IO library for C (stdio) used to limit filehandles to just a a few dozen. Solaris just recently allowed more than 256 different file descriptors per process. Note that there is no limit on how many files you can process sequentially. If you need that many files open simultaneously, then you probably should be storing your data in a proper database instead. Cheers, -Jan ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Iffor
Syntax issue (I think), I'm trying to do the following: I need to execute a block of instructions for all items in an array except for one. So if my array was: @a=(1,2,3,4,5); And we assume that I don't want to execute the block if the value of $_ is 3 ... Then, in my head, I'm looking for the WORKING (key word there) version of this: --- @a = (1,2,3,4,5); if ($_ != 3) for (@a) { print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}) } - But that if ... for line doesn't work. Neither does: for (@a, $_ != 3) {} Anyone got any ideas? I've always done this by running a standard for loop and having an if condition inside the loop .. but that seems inefficient to me right now and I'm looking for the easier way. Bill Ng ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: exhausting file handles in Win32
For the record: I am "QA" person and was asked to "see what happens" when our client software encounters a resource shortage and cannot get a file handle as it is performing its FIPS self-tests. Because I didn't understand it completely, I brought Timothy Johnson response to the engineering group here. They concur that it is likely an artificial limit, and have been nice enough to provide me a C++ app that accomplishes the task. (albeit not as elegantly as my perl script would have, imo...) Well, in terms of writing a "production application", Jan you are 100% correct, I wouldn't need all those fhs. However, if the point of writing the script is to _purposefully_ create a resource shortage on the Win32 platform, then the limit is a nuisance. Well, it's a nuisance to the novice programmer who doesn't know how to recompile their perl interpreter :) Is it fair to say that ActivePerl is preventing the end user from doing something horrible to their system and not a limitation in perl itself? At least that is what I am now understanding. Regards, Carlos Jan Dubois wrote: On Tue, 18 Apr 2006, Carlos Barbet wrote: OK, I thought perhaps using the FileHandle module would help, I rewrote the script in the fashion below. And it remains limited to 3197 using the Cygwin shell or 2045 using cmd.exe. I _assume_ the issue is something to do with perl being an interpreted language and an environment variable?? Is there a method to get this script to open say 250,000 file handles (or whatever is the theoretical limit of file handles in Win32). As one can guess, I am limited in my programming experience, thus I don't know if I am barking up the wrong tree. Perhaps a compiled language should be used for this task You are doing something wrong if you need so many filehandles open simultaneously. In standard IO library for C (stdio) used to limit filehandles to just a a few dozen. Solaris just recently allowed more than 256 different file descriptors per process. Note that there is no limit on how many files you can process sequentially. If you need that many files open simultaneously, then you probably should be storing your data in a proper database instead. Cheers, -Jan -- Gilbert Ryle: "Can I help you?" Student : "Perhaps. I'm looking for 'The Forest', but all I see are these damned trees!" ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: running a perl app
First, You're writing to a Win32 (Read: Windows) mailing list. =) Second, You're either missing or misspelling the path to the perl interpreter as your first line in every script. Your first line should always be: - #!/usr/bin/perl (or whatever the path is to your perl binary) - Hope this helps. Bill Ng -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bruce Sent: Tuesday, April 18, 2006 3:22 PM To: Perl-Win32-Users@listserv.ActiveState.com Subject: running a perl app hi.. using linux. when i do "perl foo.pl" everything works ok. when i do "./foo.pl" i get errors.. i've set the exe bit "chmod 775 foo.pl"... any idea as to what's going on... thanks -bruce ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: running a perl app
On 4/18/06, bruce wrote: hi..using linux. when i do "perl foo.pl" everything works ok. when i do"./foo.pl" i get errors.. i've set the exe bit "chmod 775 foo.pl"...any idea as to what's going on... Have you forgotten to add the shebang "#!/usr/bin/perl" (without quote - path to your Perl executable) on the first line of your script? Regards Jing Wee thanks-bruce___Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.comTo unsubscribe: http://listserv.ActiveState.com/mailman/mysubs -- -Fight back spam! Download the Blue Frog.http://www.bluesecurity.com/register/s?user=amluZ3dlZQ%3D%3D ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: exhausting file handles in Win32
On Tue, 18 Apr 2006, Carlos Barbet wrote: > Is it fair to say that ActivePerl is preventing the end user from > doing something horrible to their system and not a limitation in > perl itself? Yes, there is no guarantee that you can use Perl to exhaust any system- wide resource. Just like there is no way to use up all your swap space from Perl as long as the swap filesystem is larger than your virtual memory address space. So I guess for these kind of tasks Perl may not always be the best tool and a more low level approach may be more appropriate. Cheers, -Jan ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: running a perl app
Bruce,To determine the correct path for your perl interpretor, use: which perl-- John T SheaThere are 2 kinds of people in the world,those who finish what they start ... On 4/18/06, Ng, Bill <[EMAIL PROTECTED]> wrote: First,You're writing to a Win32 (Read: Windows) mailing list. =)Second,You're either missing or misspelling the path to the perlinterpreter as your first line in every script. Your first line should always be:-#!/usr/bin/perl (or whatever the path is to your perl binary)-Hope this helps.Bill Ng-Original Message-From: [EMAIL PROTECTED][mailto:[EMAIL PROTECTED]] On Behalf OfbruceSent: Tuesday, April 18, 2006 3:22 PM To: Perl-Win32-Users@listserv.ActiveState.comSubject: running a perl apphi..using linux. when i do "perl foo.pl" everything works ok. when i do "./foo.pl" i get errors.. i've set the exe bit "chmod 775 foo.pl"...any idea as to what's going on...thanks-bruce___Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.comTo unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Iffor
Bill Ng [bill.ng AT citigroup.com] wrote: > Syntax issue (I think), > > I'm trying to do the following: > I need to execute a block of instructions for all items in an array > except for one. > > So if my array was: > @a=(1,2,3,4,5); > And we assume that I don't want to execute the block if the value of $_ > is 3 ... > > Then, in my head, I'm looking for the WORKING (key word there) version > of this: > --- > @a = (1,2,3,4,5); > if ($_ != 3) for (@a) > { > print "something"; > &doSomething(); > print "somethingelse"; > &yada($yada{$ya}) > } > - > > But that if ... for line doesn't work. > Neither does: > > for (@a, $_ != 3) {} > > > Anyone got any ideas? I've always done this by running a standard for > loop and having an if condition inside the loop .. but that seems > inefficient to me right now and I'm looking for the easier way. Don't think you'll find anything simpler than the old standard "next if expr" : for ( @a ) { next if $_ == 3; print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}) } -- Mike Arms ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Iffor
How about this? ### use strict; use warnings; my @a = (1,2,3,4,5); foreach(@a){ unless($_ == 3){ #do something... } } ### -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ng, Bill Sent: Tuesday, April 18, 2006 12:59 PM To: perl-win32-users@listserv.ActiveState.com Subject: Iffor So if my array was: @a=(1,2,3,4,5); And we assume that I don't want to execute the block if the value of $_ is 3 ... Then, in my head, I'm looking for the WORKING (key word there) version of this: --- @a = (1,2,3,4,5); if ($_ != 3) for (@a) { print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}) } - ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Iffor
Okay, I'm a moron. I somehow missed that last line. Disregard... IMHO you probably wouldn't gain any significant performance here even if you succeeded in the syntax you are looking for because you still have to do a check for each iteration of the loop. The only thing else I can think of is if you knew the element of the list you wanted to skip ahead of time and then iterated through the array slice of the elements you wanted to keep. That might save a few cycles if the elements you throw away are towards the beginning of your array, but for the minimal amount you gain it's probably not worth it. This might be a good one to run by the guys at the beginners@perl.org mailing list. There are some guys over there that are pretty sharp when it comes to picking the right algorithm for a particular task. -Original Message- From: Timothy Johnson Sent: Tuesday, April 18, 2006 2:28 PM To: 'Ng, Bill'; perl-win32-users@listserv.ActiveState.com Subject: RE: Iffor How about this? ### use strict; use warnings; my @a = (1,2,3,4,5); foreach(@a){ unless($_ == 3){ #do something... } } ### -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ng, Bill Sent: Tuesday, April 18, 2006 12:59 PM To: perl-win32-users@listserv.ActiveState.com Subject: Iffor So if my array was: @a=(1,2,3,4,5); And we assume that I don't want to execute the block if the value of $_ is 3 ... Then, in my head, I'm looking for the WORKING (key word there) version of this: --- @a = (1,2,3,4,5); if ($_ != 3) for (@a) { print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}) } - ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Re: breaking out of a for/foreach loop...
The simplest logical way is to use a subroutine. It works and is perspicuously clear. # statement before loop mysub() ;# loop call sub mysub{ while( 1 ){ if( condition){ return} } # end while loop }# end mysub() # statement after loop Hugh Loebner On 4/18/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Its "last" what you are looking for. This will break out of the inner-most > loop. Optionally, you can put a label at the start of your loop and exit it > by name, like: > > my $foo = 0; > OUTER: while (1) { > INNER: while (1) { >$foo++; >if ($foo > 1) last INNER; > } > } > > The "last INNER" will exit the inner loop. If it were "last OUTER" it would > exit both of them immediately. This is the same thing as executing a GOTO > statement to a label outside the loops, but it seems cleaner in the code. > > -dZ. > > - Original Message - > From: [EMAIL PROTECTED] > Sent: 4/18/2006 9:58:15 AM > To: [EMAIL PROTECTED] > Cc: perl-win32-users@listserv.ActiveState.com;[EMAIL PROTECTED] > Subject: Re: breaking out of a for/foreach loop... > > > > > Bruce, > > > > You can use a "Label" and a "goto" statement. > > > > > > for (@array) > > { > > if (condition met) > > { > > goto Label; > > } > > } > > > > LABEL: > > ... > > > > Hope this helps. > > > > Dave Kazatsky > > Senior Middleware Engineer > > NSE - Solutions Engineering > > W. (732) 893-4351 > > C. (973) 865-8106 > > > > > > |-+-> > > | | "bruce" <[EMAIL PROTECTED]> | > > | | Sent by: | > > | | [EMAIL PROTECTED]| > > | | veState.com | > > | | | > > | | | > > | | 04/17/2006 10:00 PM | > > | | Please respond to bedouglas | > > | | | > > |-+-> > > > > >| > > | > >| > > | To: perl-win32-users@listserv.ActiveState.com > >| > > | cc: > >| > > | Subject: breaking out of a for/foreach loop... > >| > > > > >| > > > > > > > > > > > > ok.. > > > > i'm embarassed.. how does one break out of a for/foreach loop?? > > > > i thought it was exit/break... > > > > pointers? > > > > thanks > > > > -bruce > > > > ___ > > Perl-Win32-Users mailing list > > Perl-Win32-Users@listserv.ActiveState.com > > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > > > > > > > The information contained in this message may be CONFIDENTIAL and is for > > the intended addressee only. Any unauthorized use, dissemination of the > > information, or copying of this message is prohibited. If you are not the > > intended addressee, please notify the sender immediately and delete this > > message. > > > > > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Iffor
Thanks anyway Tim, Performance isn't really what I'm going for, just simpler code. For the past 4 years, I've been coding to get the job done, no matter how many lines it takes or how ugly it is to read, as long as it works that's fine. But recently you guys have shown me how to simplify my code and make things infinitely easier to read. So for the past day or so I've been writing a script that does some log file zipping/deleting based on last-modified time and I'm trying to do it as "neatly" as possible. Entire script runs in less than 30 seconds so performance isn't much of an issue, just looking to tidy up the code. Thanks again. Bill -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 18, 2006 5:41 PM To: Ng, Bill; perl-win32-users@listserv.ActiveState.com Subject: RE: Iffor Okay, I'm a moron. I somehow missed that last line. Disregard... IMHO you probably wouldn't gain any significant performance here even if you succeeded in the syntax you are looking for because you still have to do a check for each iteration of the loop. The only thing else I can think of is if you knew the element of the list you wanted to skip ahead of time and then iterated through the array slice of the elements you wanted to keep. That might save a few cycles if the elements you throw away are towards the beginning of your array, but for the minimal amount you gain it's probably not worth it. This might be a good one to run by the guys at the beginners@perl.org mailing list. There are some guys over there that are pretty sharp when it comes to picking the right algorithm for a particular task. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Iffor
@a = (1,2,3,4,5); for $x (@a) { if($x==3){next;} print "$x\n"; } ## You wrote: Syntax issue (I think), I'm trying to do the following: I need to execute a block of instructions for all items in an array except for one. So if my array was: @a=(1,2,3,4,5); And we assume that I don't want to execute the block if the value of $_ is 3 ... Then, in my head, I'm looking for the WORKING (key word there) version of this: --- @a = (1,2,3,4,5); if ($_ != 3) for (@a) { print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}) } - But that if ... for line doesn't work. Neither does: for (@a, $_ != 3) {} Anyone got any ideas? I've always done this by running a standard for loop and having an if condition inside the loop .. but that seems inefficient to me right now and I'm looking for the easier way. Bill Ng ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Iffor
Ng, Bill asked on April 18, 2006 12:59 PM > So if my array was: > @a=(1,2,3,4,5); > And we assume that I don't want to execute the block if the > value of $_ is 3 ... > > Then, in my head, I'm looking for the WORKING (key word there) > version of this: > --- > @a = (1,2,3,4,5); > if ($_ != 3) for (@a) > { > print "something"; > &doSomething(); > print "somethingelse"; > &yada($yada{$ya}) > } > - use strict; use warnings; my @a=(1..5); # don't like this # print grep {$_ != 3} (1 .. 5); # don't like this either # for (grep {$_ != 3} @a) { print "$_ "; } # OK # for (@a) { ($_ == 3) and next; # or: next if $_ == 3; print "$_ "; } #--Suresh __END__ ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Iffor
Read the last sentence of my email ... =) Bill Ng -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jerry Kassebaum Sent: Tuesday, April 18, 2006 6:07 PM To: perl-win32-users@listserv.ActiveState.com Subject: RE: Iffor @a = (1,2,3,4,5); for $x (@a) { if($x==3){next;} print "$x\n"; } ## You wrote: Syntax issue (I think), I'm trying to do the following: I need to execute a block of instructions for all items in an array except for one. So if my array was: @a=(1,2,3,4,5); And we assume that I don't want to execute the block if the value of $_ is 3 ... Then, in my head, I'm looking for the WORKING (key word there) version of this: --- @a = (1,2,3,4,5); if ($_ != 3) for (@a) { print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}) } - But that if ... for line doesn't work. Neither does: for (@a, $_ != 3) {} Anyone got any ideas? I've always done this by running a standard for loop and having an if condition inside the loop .. but that seems inefficient to me right now and I'm looking for the easier way. Bill Ng ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Iffor
Ng, Bill wrote: > Performance isn't really what I'm going for, just simpler code. > > For the past 4 years, I've been coding to get the job done, no > matter how many lines it takes or how ugly it is to read, as > long as it works that's fine. But recently you guys have shown > me how to simplify my code and make things infinitely easier to > read. So for the past day or so I've been writing a script that > does some log file zipping/deleting based on last-modified time > and I'm trying to do it as "neatly" as possible. Entire script > runs in less than 30 seconds so performance isn't much of an > issue, just looking to tidy up the code. Thanks again. Given your present mind-set, I suspect you'll benefit from critically thinking about the issues Damian Conway raises and addresses in his "Perl Best Practices" -- consider not just the issues he raises and his resolution of them -- consider also whether the issues he raises are valid and whether he has missed any issues. --Suresh ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Iffor
Ng, Bill wrote: Performance isn't really what I'm going for, just simpler code. If clear code is what you want, you won't get it using a 'next' as some have suggested. A 'next' syntactically looks like any other line, and is therefore not easily noticed as part of the control flow. Unless, perhaps, you put a big comment next to it. Like a 'return' or a 'die', it's easily glanced over, and should only be used for exceptional circumstances. I recommend you either: 1. Embed the 'if' inside the 'for' - this makes it clear what you are trying to do. It is not a significant performance penalty. 2. Filter out just the items you want to iterate over in advance, using 'grep'. First method: @a = (1,2,3,4,5); for (@a) { if ($_ != 3) { print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}); } } Second method: @a = (1,2,3,4,5); for (grep { $_ != 3 } @a) { print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}); } Personally, I think the second method is the clearest. You are explicitly stating what you are iterating over. You might even write: @a = (1,2,3,4,5); @a_subset = grep { $_ != 3 }; # comment about why I only want these for (@a_subset) { ... } Naming intermediate steps is good documentation. The only reason I'd use the first method is if the condition for the 'if' could change during the iteration of the loop. But I try to avoid those sorts of situations. -- Lyle Kopnicky Software Project Engineer Veicon Technology, Inc. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Iffor
[Soap box warning...] You seem to be suffering from a common perl programming psychosis: the sometimes unbearable urge to write clever perl in the fewest possible number of lines ... that infects us all from time to time... Read Damian Conway's Perl Best Practices. And when you feel the need to write clever code, read it again. Take a step back and think about the difference between the following... (besides the fact that the first way doesn't work) if ($_ != 3) for (@a) { } for (@a) { if ($_ != 3) { } } Two brackets? The for-if version is readily understandable to anyone who reads your code (including yourself 6 - 9 - 12 months later). Your if-for version, even if it did work, will confuse many, most, all, maybe even yourself 6 months later. Perl Best Practices: Chapter 1: Page 4: "... optimize your programming style for readibility; not writability. Better yet, try to optimize for comprehensibility; easy-to-read and easy-to-understand are not necessarily the same thing." And Perl Best Practices would suggest that the following is stylistically best from a readibility / comprehensibility perspective as it avoids the use of the magic variable $_ foreach my $a (@a) { if ($a != 3) { print "$a\tsomething\n"; } } Save cleverness for the times when it could make a signficant, measurable difference. Saving two brackets is useless cleverness. Concerning your if-for code that doesn't work, see "perlsyn" in the ActivePerl user guide. "Any simple statement may optionally be followed by a SINGLE modifier, just before the terminating semicolon (or block ending). The possible modifiers are: if EXPR unless EXPR while EXPR until EXPR foreach LIST" So this is legal syntax: print "$_\tsomething\n" foreach (@a); But this is not because the if block is not a simple statement. if ($_ != 3) { print "$_\tsomething\n"; } foreach (@a); Maybe the closest to your envisioned clever solution is the "apply" function available in the List::MoreUtils perl module. See the last example in the following that uses "apply". use strict; use warnings; my @a = (1,2,3,4,5); print "$_\tsomething 1\n" foreach (@a); # this isn't legal perl syntax... # #if ($_ != 3) { # print "$_\tsomething 1\n"; #} foreach (@a); print "\nstandard foreach loop with interior if\n"; foreach my $a (@a) { if ($a != 3) { print "$a\tsomething 2\n"; } } print "\nstandard foreach loop with next\n"; foreach my $a (@a) { next if ($a == 3); print "$a\tsomething 3\n"; } print "\nList::MoreUtils apply method\n"; use List::MoreUtils qw(apply); apply { print "$_\tsomething 4\n" if ($_ != 3) } @a; Regards, ... Dewey "Ng, Bill" <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 04/18/2006 03:59 PM To cc Subject Iffor Syntax issue (I think), I'm trying to do the following: I need to execute a block of instructions for all items in an array except for one. So if my array was: @a=(1,2,3,4,5); And we assume that I don't want to execute the block if the value of $_ is 3 ... Then, in my head, I'm looking for the WORKING (key word there) version of this: --- @a = (1,2,3,4,5); if ($_ != 3) for (@a) { print "something"; &doSomething(); print "somethingelse"; &yada($yada{$ya}) } - But that if ... for line doesn't work. Neither does: for (@a, $_ != 3) {} Anyone got any ideas? I've always done this by running a standard for loop and having an if condition inside the loop .. but that seems inefficient to me right now and I'm looking for the easier way. Bill Ng ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: exhausting file handles in Win32
I'd try the following: #!/usr/bin/perl -w use strict; use File::Spec; use POSIX qw(tmpnam); use Win32API::File; my $num = shift || 10; my (@tempfiles, @temphandles); #impatience $| = 1; END { map {CloseHandle $_ } @temphandles; #hubris map {unlink $_ } @tempfiles; }; my $temp_dir = File::Spec->tmpdir(); while($num--) { #laziness my $path = File::Spec->rel2abs(File::Spec->catfile($temp_dir, tmpnam() )); my $hObject= Win32API::File::createFile( $path, 'qrwtc' ); push @temphandles, $hObject; push @tempfiles, $path; print "object: $hObject :", $^E, "\n"; } sleep(60); I was able to open 100,000 filehandles with no problem, though that unlink kinda acts weird. DeleteFile might work, but I figured this was enough to start you in the right direction. cabz wrote: Hello! I am new perl (again). I am performing QA on software developed at my company. My task is to try to exhaust all file handles on the Win32 platform (Win2K and WinXP) and see how our software behaves. With the code below, I am able to open no more than 2045 file handles under a cmd.exe shell and 3197 under a Cygwin shell. Regards, Carlos #!/usr/bin/perl -w if([EMAIL PROTECTED]) { print "usage: filehandles \n"; exit; } $totalfhs = shift; #I could use $ARGV[0]; $i = 1; while ($i == $totalfhs || $i < $totalfhs) { open $ar[$i], ">_$i.tmp" or die "Could not open $i"; $i++; } print $i-1 ." filehandles are open, hit any key to close \n"; $_ = ; $i--; #cheesy but it is what is needed here while ($i > 0) { close($ar[$i]) or die "\n\nError closing: $!"; unlink("_$i.tmp") or die "\n\nError deleting: $!"; $i--; } ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: running a perl app
To determine the correct path for your perl interpretor, use: which perl -- Please give me a context. C: which perl $x = which perl; c: perl which perl I'm missing something here. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Opening an Excel workbook with links to other data sources
Hello, When I manually open an Excel file, it bring up a dialog box stating that the "workbook contains links to other data sources" and asking if the data should be updated. The following perl code brings up a similar dialog box: use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Open($file); # open Excel file my $Sheet = $Book->Worksheets(1); # select worksheet number 1 $Book->Close; How do I answer "No" from within the perl code? Thanks, --Suresh ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: running a perl app
It's the cygwin/unix command. It tells u which object in ur path will be exectued. D:\autocrat>which perl /c/perl/bin/perl -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: running a perl app
- Original Message - From: "Jerry Kassebaum" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; Sent: Wednesday, April 19, 2006 1:09 PM Subject: Re: running a perl app > >To determine the correct path for your perl interpretor, use: > > >which perl > > >-- > > Please give me a context. > Note that the original post pertained to a Unix-like system (not Windows) - and the answer you've quoted above pertains primarily to Unix-like systems. On Unix -like systems if you were to enter 'which perl' at the command line, then the fully qualified path to the perl executable would be returned. On windows the same command could successfully be run in the msys shell, or in Cygwin's bash shell - and perhaps some other shells, too - but not the cmd.exe shell, unless you've installed a which.exe such as that available from http://gnuwin32.sourceforge.net/packages.html (as I have done): E:\downloads>which perl D:/perl58_M/5.8.8/bin/perl.EXE Cheers, Rob ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs