Re: system() Conundrum
After further research I found this problem is affecting more users than I realized. Most of them have file associations set that run UltraEdit for the files we're commonly downloading. So this obscured the problem, since when it occurs it results in Windows falling back to the default application for that file. However, some files we download have no extension or one associated with another application and when I had people test that scenario the problem surfaced for everyone but one other user and myself. It seems to be related to the quotes around the path - which are necessary since "program files" has a space in the middle. BTW, we're all running either Win2K or XP. As a work around, the following code works on my machine: my $ProcessObj; my @temp = split( /\\/, $EDITOR ); my $exe = pop( @temp ); Win32::Process::Create($ProcessObj, $EDITOR, "$exe $file", 0, NORMAL_PRIORITY_CLASS, "." ) || WinError(); Next week I'll give this to the other people in my group to see if it solves the problem. Thanks for everyone's help. Roy Olsen What about using Win32::Process::Create? - Original Message - From: "Roy Olsen" <[EMAIL PROTECTED]> To: Sent: Friday, July 01, 2005 11:56 AM Subject: system() Conundrum > > I have a Perl script that receives programs and other files from a host > system for editing. Once the file is transferred the script launches my > text editor and passes it the name of the file. It works fine for me and > several colleagues. However, on one user's brand new system (with XP Pro > and Perl v5.8.6) it won't launch the editor, instead it brings up the > windows dialog for selecting which program to use. > > To make it flexible, I read an environment variable that contains the path > to the editor. Here's the relevant bits of code: > > $EDITOR = $ENV{BASIC_EDITOR}; > ... > if ($EDITOR) { >system( "start $EDITOR $file" ); > } > > It seems that windows is seeing something like: > > start SomeFile > > with the editor path being omitted. To track down the cause of this I > setup some one line test scripts we could run on this user's system. This > example launches Win.ini in notepad: > > system( "start \"c:/program files/ultraedit/uedit32.exe\" > c:/windows/WIN.ini" ); > > Again, somehow the program name is disappearing or being ignored. However, > running this next script in "c:\program files\UltraEdit" opens Win.ini in > UltraEdit like I'ld expect: > > system( "start uedit32.exe c:/windows/WIN.ini" ); > > Why would it work this way and only on one user's system?? > > Roy Olsen > > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Why is this a problem?
Hugh Loebner wrote: > foreach my $fhkey ( keys %fh){ > open ( $fh{$fhkey}, ">$fhkey" ) ; > } Nobody mentioned this yet: Since you want your filehandles to be unique, why not use the key of the hash instead of the value? In other words, change the above to: foreach my $fhkey ( keys %fh){ open ( $fhkey, ">$fhkey" ) ; } - Mark. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Why is this a problem?
Because the first parameter passed to open is the file handle. In the first case, there are 3 file handles: 1,2,3. In the second case, the same file handle is used for each file, always ‘1’. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugh Loebner Sent: Friday, July 01, 2005 9:21 AM To: Perl-Win32-Users Mailing List; activeperl@listserv.ActiveState.com Subject: Why is this a problem? Hello perl gurus, I spent almost a whole day solving this problem. However, I wonder why it's a problem. # use strict; no strict "refs" ; # this works fine, produces three files, aa , bb, cc with contents 'xxx aa xxx' etc my %fh = ( aa => 1, bb =>2, cc => 3) ; # note that each instance of $fh{$fhkey} has a different value foreach my $fhkey ( keys %fh){ open ( $fh{$fhkey}, ">$fhkey" ) ; } foreach my $fhkey ( keys %fh ){ print { $fh{$fhkey} } "xxx $fhkey xxx \n" ; # note file handle $fh{$fhkey} has to be in a block } ; foreach my $fhkey ( keys %fh ){ close $fh{$fhkey} ; } # # The following program (which is what I started out with) will NOT work properly: Each element of %fh has a value of 1 # Why doesn't this work properly? - all statements write to one file # my %fh = ( aa => 1, bb =>1, cc => 1) ; # note - only change, each $fh{} has value of 1 foreach my $fhkey ( keys %fh){ open ( $fh{$fhkey}, ">$fhkey" ) ; } foreach my $fhkey ( keys %fh ){ print { $fh{$fhkey} } "xxx $fhkey xxx \n" ; # note file handle $fh{$fhkey} has to be in a block } ; foreach my $fhkey ( keys %fh ){ close $fh{$fhkey} ; } # Hugh Loebner ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Why is this a problem?
Hugh Loebner wrote: > Hello perl gurus, > > I spent almost a whole day solving this problem. However, I wonder why > it's a problem. > # > # The following program (which is what I started out with) will NOT work > properly: Each element of %fh has a value of 1 > # Why doesn't this work properly? - all statements write to one file > # > > > my%fh = ( aa => 1, bb =>1, cc => 1) ;# note - only change, each > $fh{} has value of 1 The proper way to do this would be to use Symbol: use Symbol; my %fh = (aa => gensym, bb => gensym, cc => gensym); Barring that, you could use a ref to typeglob : my %fh = (aa => \*1, bb => \*2, cc => \*3); If you use 1,1,1 instead of 1,2,3 - then they'll all be pointing to the same symbolic reference and essentially the same file. > foreach my $fhkey ( keys %fh){ > open ( $fh{$fhkey}, ">$fhkey" ) ; > } > > foreach my $fhkey ( keys %fh ){ > print { $fh{$fhkey} } "xxx $fhkey xxx \n" ;# note file handle > $fh{$fhkey} has to be in a block > } ; > > foreach my $fhkey ( keys %fh ){ > close $fh{$fhkey} ; > } -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Why is this a problem?
At 09:20 AM 7/1/05 -0400, [EMAIL PROTECTED] wrote: ># this works fine, produces three files, aa , bb, cc with contents 'xxx aa >xxx' etc > >my %fh = ( aa => 1, bb =>2, cc => 3) ; # note that each instance of >$fh{$fhkey} has a different value > >foreach my $fhkey ( keys %fh){ >open ( $fh{$fhkey}, ">$fhkey" ) ; >} In this case, ur successively opening three file handles, with the values, 1, 2, and 3. If you want the file handle to be the name of the key, it should be $fhkey not $fh{$fhkey}. ># The following program (which is what I started out with) will NOT work >properly: Each element of %fh has a value of 1 ># Why doesn't this work properly? - all statements write to one file >my %fh = ( aa => 1, bb =>1, cc => 1) ; # note - only change, each $fh{} has >value of 1 >foreach my $fhkey ( keys %fh){ >open ( $fh{$fhkey}, ">$fhkey" ) ; >} Here ur opening the same file handle, 1, three times. -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede males" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Why is this a problem?
Title: Message See answers: my %fh = ( aa => 1, bb =>2, cc => 3) ; # note that each instance of $fh{$fhkey} has a different valueforeach my $fhkey ( keys %fh){ open ( $fh{$fhkey}, ">$fhkey" ) ;## >so, you open 3 file handles, one named "1", one named "2", and one named "3" } >non-working code my %fh = ( aa => 1, bb =>1, cc => 1) ; # note - only change, each $fh{} has value of 1foreach my $fhkey ( keys %fh){ open ( $fh{$fhkey}, ">$fhkey" ) ; } ## Mmmm, because you only open one uniquely named file handle? Specifically, named "1"? ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Why is this a problem?
Hello perl gurus, I spent almost a whole day solving this problem. However, I wonder why it's a problem. # use strict; no strict "refs" ; # this works fine, produces three files, aa , bb, cc with contents 'xxx aa xxx' etc my %fh = ( aa => 1, bb =>2, cc => 3) ; # note that each instance of $fh{$fhkey} has a different value foreach my $fhkey ( keys %fh){ open ( $fh{$fhkey}, ">$fhkey" ) ; } foreach my $fhkey ( keys %fh ){ print { $fh{$fhkey} } "xxx $fhkey xxx \n" ; # note file handle $fh{$fhkey} has to be in a block } ; foreach my $fhkey ( keys %fh ){ close $fh{$fhkey} ; } # # The following program (which is what I started out with) will NOT work properly: Each element of %fh has a value of 1 # Why doesn't this work properly? - all statements write to one file # my %fh = ( aa => 1, bb =>1, cc => 1) ; # note - only change, each $fh{} has value of 1 foreach my $fhkey ( keys %fh){ open ( $fh{$fhkey}, ">$fhkey" ) ; } foreach my $fhkey ( keys %fh ){ print { $fh{$fhkey} } "xxx $fhkey xxx \n" ; # note file handle $fh{$fhkey} has to be in a block } ; foreach my $fhkey ( keys %fh ){ close $fh{$fhkey} ; } # Hugh Loebner ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Importing Identifiers from Main::
L. Neil Johnson wrote: > Thanks for the coding critique. You're right. Any idea if either form > evaluates faster? $#array or scalar @array? Find out for yourself: use Benchmark; ... -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Importing Identifiers from Main::
On Thursday, June 30, 2005 09:33:23 +0200, Johan Lindstrom [SMTP:[EMAIL PROTECTED] wrote: > This is what I meant when I said a hash is a good solution to this problem. > You're not really interested in the order, you want to access each element > by a convenient name. > > It sounds like a bit of data to keep in memory, so going from an array to a > hash may not be feasible because of that, but if it is it would look like > this instead: > > $trade[$i]->{"time_elapsed"} > > If your available memory can take this hit, I'd consider that approach a > lot more maintainable. If not, go with either exported constants or simply > $UPPER_CASE_VARIABLES as named indices into the array. I didn't mean to ignore this approach. I really like it because: 1) The symbols are contained in the hash and don't have to be imported. And, 2) It's self-documenting (presume this is what you meant by "maintainable) -- very easy to read. The memory may not support this design for this particular array, but I will use it on one, maybe two, smaller arrays. Thank you very much. > And to me it looks like the solution would be more clear with each record > being an object, but if you're not familiar with OO, don't start > introducing it in this program. Try it out with something small and new. > > http://www.manning.com/books/conway is excellent. Thanks for the reference. I remember Conway as the author of Switch.pm. Should be good. I appreciate the investment of time and quality of your suggestions. --Neil ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Importing Identifiers from Main::
On Thursday, June 30, 2005 1:25 AM, $Bill Luebkert [SMTP:[EMAIL PROTECTED] wrote: > > You could start that package off with a 'package main;' stmt which will > put you in the same namespace as the calling module. Good idea. This obviates the need to import identifiers. Rob suggested a similar approach yesterday. > You can use an array's scalar context to make this easier to read : > for (my $i = 0; $i < @{$rT}; $i++) { Thanks for the coding critique. You're right. Any idea if either form evaluates faster? $#array or scalar @array? > # using constants (but you have to export them to the other module like > your glob refs): > > use constant xbi => 0;# index into data arrays, begin time > use constant xei => 1;# index into data arrays, end time > use constant xi => 2;# indicator > use constant xs => 3;# signal > use constant xa => 4;# amplitude > use constant xt => 5;# elapsed time > use constant xr => 6;# trend I prefer this approach, notwithstanding the need to copy the definitions into the module(s) that use them: 1) The indices really are constants, and the pragma makes that clear. 2) Dropping the "$" from the symbol in the anonymous array index makes it clear when reading the body of the code that the index isn't going to change (I probably would use all caps in the identifiers to emphasize this). 3) The identifiers are shorter by one character. 4) If the compiler in-lines the constant (or subroutine that coughs up the constant), it may execute faster. > # using a hash: > > my %IX = ( > xbi => 0; # index into data arrays, begin time > xei => 1; # index into data arrays, end time > xi => 2;# indicator > xs => 3;# signal > xa => 4;# amplitude > xt => 5;# elapsed time > xr => 6;# trend > }; This is also a good idea in that the identifiers are passed with the array, and there's no need to define them in each module. However, Johanes Lindstrom's method of using anonymous hashes appeals to me because it's so natural to read. Bill, I really appreciate your commentary on the code and the expert suggestions you have made -- as usual. -Neil ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs