[28603] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9967 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 14 14:05:45 2006

Date: Tue, 14 Nov 2006 11:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 14 Nov 2006     Volume: 10 Number: 9967

Today's topics:
    Re: compare two string and make some operation on it? <uri@stemsystems.com>
        Confused about namespaces <anon40629@hotmail.com>
        Hashes and subroutines <deadpickle@gmail.com>
    Re: how do i update one section of a page leaving rest? <zentara@highstream.net>
    Re: how do i update one section of a page leaving rest? <uri@stemsystems.com>
        how to automate installation of a MSI file using perl <hara.acharya@gmail.com>
    Re: how to automate installation of a MSI file using pe <john@castleamber.com>
    Re: I have no problems eating cereal...after it softens <uri@stemsystems.com>
    Re: Masking/Hiding a password in Perl Source <nospam@example.com>
        Newbie with simple File handling problem <jasongilbertuk@hotmail.com>
    Re: Newbie with simple File handling problem <jasongilbertuk@hotmail.com>
    Re: Newbie with simple File handling problem <glex_no-spam@qwest-spam-no.invalid>
    Re: Newbie with simple File handling problem <uri@stemsystems.com>
    Re: perl exceptions and return value in finally block <glex_no-spam@qwest-spam-no.invalid>
        running dos commands from perl script edwells@statestreet.com
    Re: running dos commands from perl script <spamtrap@dot-app.org>
    Re: running dos commands from perl script <critterstown@googlemail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 14 Nov 2006 13:51:21 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: compare two string and make some operation on it?
Message-Id: <x7ac2tn9p2.fsf@mail.sysarch.com>

>>>>> "FB" == Ferry Bolhar <bol@adv.magwien.gv.at> writes:

  FB> Paul Lalli:
  >>> Well, special inside of sort blocks, OK. But else (in this example)?

  FB> [...]

  FB> Well, you showed us that $a and $b are excluded from 'strict vars'.
  FB> Right, but nothing new here (in addition, within the sort block, they
  FB> are localized and aliased to the n'th and n+1'th argument of the sort
  FB> list for each n'th iteration over the list). So far, so well.

that is actually wrong. sort doesn't grab sequential pairs and sort
that. that would be a bubble sort which is very slow. 

 perl -le 'print sort { print "A $a B $b" ; $a <=> $b } 3, 2, 4, 1, 5'
A 3 B 2
A 4 B 1
A 2 B 1
A 2 B 4
A 3 B 4
A 1 B 5
A 5 B 2
A 5 B 3
A 5 B 4
12345

  FB> But what has this "speciality" to do with the example given by the
  FB> OP? Why do you not want to use $a and $b in examples like this
  FB> one?

just because they are not checked under strict it is a bad idea to use
them. that is good enough. on top of that single letter var names are
bad in general as they are hard to search for and replace and have little
if any meaning (outside the math indexes like i and j). for short
examples you can use $x and $y or other names but it is just good
practice to not use $a and $b outside sort in ANY code.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Tue, 14 Nov 2006 09:45:49 -0800
From: "Mark" <anon40629@hotmail.com>
Subject: Confused about namespaces
Message-Id: <1163526343.791944@bubbleator.drizzle.com>

Good morning.

I clearly do not understand namespaces.

I was attempting to subclass a module from CPAN, and I continually
ran into errors relating to @ISA. So I decided to try some _very_ simple
package examples, and I found a few here:

http://www.netalive.org/tinkering/serious-perl/#namespaces

I grabbed their first example and tried to run it. I received essentially
the same error I had been receiving before:

Can't locate Sophie.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib 
 .) at test.pl line 7.
BEGIN failed--compilation aborted at test.pl line 7.

Can someone please tell me what I am doing wrong? Here is the sample code:

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
package Sophie;
sub say_hello {
    print "Hi World!";
}

package Clara;
use Sophie;           # loads the package but does NOT import any methods
#say_hello();          # blows up
Sophie->say_hello();  # correct usage
#Sophie::say_hello();  # works, but not for inherited methods
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Thanks
-Mark





------------------------------

Date: 14 Nov 2006 10:52:33 -0800
From: "deadpickle" <deadpickle@gmail.com>
Subject: Hashes and subroutines
Message-Id: <1163530353.104196.298570@k70g2000cwa.googlegroups.com>

What I want to do is search a text file for the correct station ID. I
hope this is clearer from the code. I run it and it returns the correct
values but I get the warning "Odd number of elements in hash assignment
at search1.pl line 15, <ID> line 6." Im not sure what this means. Any
help?
Also I want to pass a few variables to a subroutine but am not sure how
to do this.

Text file
===================================================================
KLNK 261412Z 04011KT 3/4SM R36/5500VP6000FT BR OVC003 07/06 A2992 RMK
AO2
KCHS 131656Z 15009KT 10SM -RA FEW027 BKN044 24/20 A2994 RMK AO2 RAB44
SLP137 P0000 T02440200
KEMP 101653Z AUTO 33016KT 10SM BKN065 BKN090 07/00 A2993 RMK AO2 PK WND
33027/1559 SLP136 T00670000
KHSI 101653Z AUTO 36015KT 7SM OVC007 03/01 A3013 RMK AO2 SLP214
T00280006
KRSL 101653Z AUTO 35021G27KT 10SM BKN018 OVC030 06/00 A3009 RMK AO2 PK
WND 35027/1649 SLP194 T00560000
KRWL 101653Z AUTO 25018G22KT 10SM CLR M02/M07 A3027 RMK AO2 SLP273
T10171067

My Program
===================================================================
#=========================================================
#	This code is used to search a text file for the correct
# ASOS sites are then runs the metarcode subroutine to
# create the placefile that GRLevel3 needs.
#=========================================================
use strict;
use warnings;
$\ = "\n";
# Open the text file containing the stations
open (ID, "stations.txt");
while (my $stations = <ID>) {
	my @station = split (/\n/,$stations);  # enter each line into an array
	foreach (@station) {  # Search the array for the correct stations
		print $_;
		if (my %stid = $_ =~ m/^KRWL/) {
			my $id = $_;
			print $id;
		}
	}
}

This is a prelimanary program so it does not pass the variables to the
subroutine. I want to pass three variables to the subroutine: 1) the
array resulting from the search;2) the latitude of the site; 3) the
longitude. THe lat and long need to be inserted into a variable on the
subroutine and so does the array. I am not sure on how to do this and
any help wouild be great. Thanks.



------------------------------

Date: Tue, 14 Nov 2006 16:22:29 GMT
From: zentara <zentara@highstream.net>
Subject: Re: how do i update one section of a page leaving rest?
Message-Id: <0jqjl294s478j7f5vm17jcbi76d7q2o8hb@4ax.com>

On 13 Nov 2006 23:13:54 -0800, "gavino" <bootiack@yahoo.com> wrote:

>George Bush: fixed clinton inflation, ficed 9-11, freed two countries,
>vote republican.  Europe can copy the USA but has a long way to go
>until its living standard or schools catch up to usa.

Uh.. I think you have a few typos in there

George Bush: ran up trillion dollar war dept, so his corpoate buddies
can get out of their stock market slump.  And since he passed tax laws
that prevents the rich from being taxed, he will now let the democrats
fix the debt, by inflation. Of course he will blame the dems for the
inflation.  

"ficed 9-11" ? 
I think you mean "f*cked". Osama is still out there. The Taliban are
coming back, since the US went on a goose chase in Iraq. 
Iraq has made the US people lose faith in it's leadership, so now
it will be even harder to launch overseas operations. Bush made
terrorism worse, by giving Al-Queda a foothold in Iraq, and plenty
of practice learning how to make IEDs and evading hightech American
eavesdropping and surveillance.

"freed two countries" ? 
I think you meant "screwed 2 countries" who are now decimated by civil
war, and have seen more civilian deaths than Saddam or the Taliban ever
caused.

The purpose of government is to maintain order and the people's faith
in it.
Bush caused more disorder and destroyed faith in government. 
That is bad. 
What's worse, he was told beforehand it would happen, and
he ignored it.

Is he dumb? No.... he did it so his corporate buddies could profit by
running up a trillion dollar debt. He just pretends to be ignorant.

  

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


------------------------------

Date: Tue, 14 Nov 2006 13:43:11 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: how do i update one section of a page leaving rest?
Message-Id: <x7ejs5na2o.fsf@mail.sysarch.com>

>>>>> "g" == gavino  <bootiack@yahoo.com> writes:

  g> On Nov 9, 12:03 am, Uri Guttman <u...@stemsystems.com> wrote:
  >> >>>>> "g" == gavino  <booti...@yahoo.com> writes:  g> Uri Guttman wrote:
  >> >> >>>>> "g" == gavino  <booti...@yahoo.com> writes:
  >> >>
  g> Michele Dondi wrote:
  >> >> >>
  >> >> >> Oh, you should have specified these details in the first place. Then
  >> >> >> it would have been easier to help you. So here's another try: open the
  >> >> >> sources for that web app in your favourite editor and write some code
  >> >> >> that will delete the section you don't like, and update it with the
  >> >> >> new content.
  >> >>
  g> You realise you come off as an idiot when you talk like this?
  >> >>
  >> >> nah, he was just treating you like the idiot you are. big difference.
  >> >>
  g> vote republican.
  >> >>
  >> >> more proof of your idiocy.
  >> >>
  >> >> uri
  >> >>
  >> >> --
  g> you are useless
  >> 
  >> nah, just useless to you. and you don't count. i voted yesterday and
  >> that turned out to be very useful to our country.
  >> 
  >> too bad to be you. have fun if you can. learn python. go bother them.

  g> Don't bother me with your eurotrash blather.
  g> If you don't know be silent.  Less people will know you are stupid.

nah, i am from brooklyn and punks like you are insulted all the time
cause you earn it. keep it up and you may also get a bronx cheer!

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: 14 Nov 2006 09:19:48 -0800
From: "king" <hara.acharya@gmail.com>
Subject: how to automate installation of a MSI file using perl
Message-Id: <1163524788.058562.124060@h48g2000cwc.googlegroups.com>

Is dere any module in perl using which we can automate the installation
of MSI file.



------------------------------

Date: 14 Nov 2006 17:58:02 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: how to automate installation of a MSI file using perl
Message-Id: <Xns987B79BC8A110castleamber@130.133.1.4>

"king" <hara.acharya@gmail.com> wrote:

> Is dere any module in perl using which we can automate the installation
> of MSI file.

http://www.google.com/search?q=msi%20command%20line

perldoc -f system

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


------------------------------

Date: Tue, 14 Nov 2006 13:42:06 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: I have no problems eating cereal...after it softens. Why is replacing a simple string so hard then?
Message-Id: <x7irhhna4h.fsf@mail.sysarch.com>

>>>>> "B" == Brian  <bwilkins@gmail.com> writes:

  B> Dave Weaver wrote:
  >> On 25 Oct 2006 03:09:29 -0700, Brian  Wilkins <bwilkins@gmail.com> wrote:
  >> >  OBE = Overcome By Events.
  >> >
  >> >  And yes it was stated untested. I guess you were too busy sitting on
  >> >  your high horse to notice this line:
  >> >
  >> >  "Like so (caution not tested): "

even untested code can be reviewed.

  >> If code that is posted in a public forum such as this has problems, it
  >> is good for those problems to be pointed out in the same public forum
  >> so that people who don't know Perl so well can won't be mislead into
  >> thinking it's perfectly acceptable code, and then go and use it
  >> themselves.

  B> Your comments were degrading and were not toward the true spirit of
  B> Perl. Your attitude is reminiscent of many cocky Open Source
  B> folks. I hope you had fun at picking apart the crappy code that I
  B> admittedly wrote. Your comments, while technically correct, were
  B> out of context and you should learn a better way to constructively
  B> criticize rather than pick apart code that was admittedly not
  B> tested.

huh? you claim to know the true spirit of perl but do you know the true
spirit of this group? posted code (tested or not) is ALWAYS up for any
comments or review here. even if you don't care, others do and many can
learn from decent code criticism. so as he said, if you don't want to
have your code reviewed, don't post it in a public forum.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Tue, 14 Nov 2006 08:25:24 -0800
From: "Chris G." <nospam@example.com>
Subject: Re: Masking/Hiding a password in Perl Source
Message-Id: <4559edf7$0$97233$892e7fe2@authen.yellow.readfreenews.net>

Actually, you're absolutely correct on the sniffing the telnet
connections.  Sadly, several of us have not been able to convince our
organization's leadership that moving to SSL for web interfaces and SSH
for command-line sessions is necessary on our network equipment.  I like
your idea, though I am not exactly sure I understand how you implement
that in an automated fashion.  I like the example you gave, though.  It
gives me a great start on my next iteration of this script, which
includes command-line options for usernames, passwords, and more.
(Simple stuff, I know).  We don't use TACACS or RADIUS at the moment,
but that's on the project list.

Thanks for the help!

Chris

Craig K wrote:
> Craig K wrote:
>> This is true, but the OP asked for hiding the passwords within the
>> script which was the request that I offered a solution to.  Also, if
>> you are running telnet, as the OP mentioned,  I can put a sniffer on
>> the segment and have the password within 10 seconds.
>>
> 
> In looking further... I think I mixed my newsgroup messages.  The OP
> only mentions connects to devices, not telnets.  Anyway, let me correct
> my statement to be that any unencrypted connection (i.e. telnet, ftp,
> etc) could have the password gathered in short order with a sniffer.
> 


------------------------------

Date: 14 Nov 2006 09:52:49 -0800
From: "JasonGilbertUK" <jasongilbertuk@hotmail.com>
Subject: Newbie with simple File handling problem
Message-Id: <1163526769.455841.202770@b28g2000cwb.googlegroups.com>

Hi All,

I'm working through "Learn Perl in a weekend" and have hit issues in
the file handling section. The code below is taken from the book and is
a simple demo of opening / reading / closing a file.

Everytime I run it, it fails at line 2 when attempting to lock the
file. I have no other apps open that are accessing the file new.txt.
Can anyone tell me what the problem is.

For reference, I'm running under Windows XP Professional, with Admin
privilages and am using ActivePerl 5.8.8

open (sHANDLE, "<c:\\perl\\eg\\weekend\\new.txt") || die ("Cannot open
new.txt");
flock (sHANDLE, LOCK_EX) || die("Cannot lock new.txt");
$onecharacter = getc (sHANDLE);
print $onecharacter
flock (sHANDLE, LOCK_UN) || die("Cannot unlock new.txt");
close (sHANDLE) || die ("Cannot close new.txt");
print "Press <ENTER> to continue...";
<>

Output from the program below, together with directory listing of the
file I'm trying to open.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

c:\perl\eg\weekend>files.pl
Cannot lock new.txt at c:\perl\eg\weekend\files.pl line 5.

c:\perl\eg\weekend>dir n*.txt
 Volume in drive C has no label.
 Volume Serial Number is BCB0-E820

 Directory of c:\perl\eg\weekend

14/11/2006  16:41                11 namesfile.txt
14/11/2006  17:05                40 new.txt
               2 File(s)             51 bytes
               0 Dir(s)  23,670,530,048 bytes free

c:\perl\eg\weekend>attrib new.txt
           C:\perl\eg\weekend\new.txt

c:\perl\eg\weekend>



------------------------------

Date: 14 Nov 2006 10:24:32 -0800
From: "JasonGilbertUK" <jasongilbertuk@hotmail.com>
Subject: Re: Newbie with simple File handling problem
Message-Id: <1163528672.009776.195520@f16g2000cwb.googlegroups.com>

Spent another 45 mins on it and cracked it.
LOCK_EX and LOCK_UN are both coming out as 0 for some reason. Replacing
these with 2 and 8 respectively and fixing the print statement (which
was missing a ;) and it's all working now.

JasonGilbertUK wrote:

> Hi All,
>
> I'm working through "Learn Perl in a weekend" and have hit issues in
> the file handling section. The code below is taken from the book and is
> a simple demo of opening / reading / closing a file.
>
> Everytime I run it, it fails at line 2 when attempting to lock the
> file. I have no other apps open that are accessing the file new.txt.
> Can anyone tell me what the problem is.
>
> For reference, I'm running under Windows XP Professional, with Admin
> privilages and am using ActivePerl 5.8.8
>
> open (sHANDLE, "<c:\\perl\\eg\\weekend\\new.txt") || die ("Cannot open
> new.txt");
> flock (sHANDLE, LOCK_EX) || die("Cannot lock new.txt");
> $onecharacter = getc (sHANDLE);
> print $onecharacter
> flock (sHANDLE, LOCK_UN) || die("Cannot unlock new.txt");
> close (sHANDLE) || die ("Cannot close new.txt");
> print "Press <ENTER> to continue...";
> <>
>
> Output from the program below, together with directory listing of the
> file I'm trying to open.
>
> Microsoft Windows XP [Version 5.1.2600]
> (C) Copyright 1985-2001 Microsoft Corp.
>
> c:\perl\eg\weekend>files.pl
> Cannot lock new.txt at c:\perl\eg\weekend\files.pl line 5.
>
> c:\perl\eg\weekend>dir n*.txt
>  Volume in drive C has no label.
>  Volume Serial Number is BCB0-E820
>
>  Directory of c:\perl\eg\weekend
>
> 14/11/2006  16:41                11 namesfile.txt
> 14/11/2006  17:05                40 new.txt
>                2 File(s)             51 bytes
>                0 Dir(s)  23,670,530,048 bytes free
>
> c:\perl\eg\weekend>attrib new.txt
>            C:\perl\eg\weekend\new.txt
> 
> c:\perl\eg\weekend>



------------------------------

Date: Tue, 14 Nov 2006 12:45:53 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Newbie with simple File handling problem
Message-Id: <455a0efd$0$10301$815e3792@news.qwest.net>

JasonGilbertUK wrote:
> Spent another 45 mins on it and cracked it.
> LOCK_EX and LOCK_UN are both coming out as 0 for some reason. 

For some reason? The reason is that they're not defined.

 >Replacing
> these with 2 and 8 respectively and fixing the print statement (which
> was missing a ;) and it's all working now.

perldoc perlopentut

perldoc Fcntl



use Fcntl qw(:DEFAULT :flock);

>> open (sHANDLE, "<c:\\perl\\eg\\weekend\\new.txt") || die ("Cannot open
>> new.txt");

Include the reason why, in the die:

my $file = 'c:/perl/eg/weekend/new.txt';
open( my $fh, '<', $file ) or die "Can't open $file: $!";

>> flock (sHANDLE, LOCK_EX) || die("Cannot lock new.txt");
Same here.. die "Cannot lock new.txt: $!";
>> $onecharacter = getc (sHANDLE);
>> print $onecharacter
>> flock (sHANDLE, LOCK_UN) || die("Cannot unlock new.txt");
and here..
>> close (sHANDLE) || die ("Cannot close new.txt");
and probably here.
>> print "Press <ENTER> to continue...";


------------------------------

Date: Tue, 14 Nov 2006 13:56:33 -0500
From: Uri Guttman <uri@stemsystems.com>
To: "JasonGilbertUK" <jasongilbertuk@hotmail.com>
Subject: Re: Newbie with simple File handling problem
Message-Id: <x764dhn9ge.fsf@mail.sysarch.com>

>>>>> "J" == JasonGilbertUK  <jasongilbertuk@hotmail.com> writes:

  J> Hi All,
  J> I'm working through "Learn Perl in a weekend" and have hit issues in
  J> the file handling section. The code below is taken from the book and is
  J> a simple demo of opening / reading / closing a file.

the weekend is over and you don't know perl yet? get a better and longer
reading book!

  J> open (sHANDLE, "<c:\\perl\\eg\\weekend\\new.txt") || die ("Cannot open
  J> new.txt");
  J> flock (sHANDLE, LOCK_EX) || die("Cannot lock new.txt");

where is LOCK_EX defined? since i bet you didn't use strict that will be
the string 'LOCK_EX' which will have a value of 0. your other post
figured out the 0 part but did the wrong thing by hardwiring constants.

so see if that book tells you how to get those constants defined. hint:
you have to load a module which defines them. 

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Tue, 14 Nov 2006 11:27:46 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: perl exceptions and return value in finally block
Message-Id: <4559fcaf$0$3567$815e3792@news.qwest.net>

Ben Morrow wrote:
> Quoth rusland@scn.ru:
>>> You can't "return" from a try.
>>>
>>> my $ret;
>>> try {
>>>    if( condition ) { $ret = 'abc' }
>>>    elsif( condition2 ) { $ret='lmnop'; }
>> Yes, I can use return at try, for example:

OK, in your original example you had the try in an eval, I think. You 
can 'return' from a subroutine.

>> #!/usr/bin/perl
>>
>> use strict;
>> use Error qw(:try);
>>
>> sub apple {
>>     try {
>>         return 'fruit'  if $_[0] eq 'apple';
>>         return 'possibly a fruit';
>>     }
>>     finally {
>>         print 'finally at apple(): ';
>>     };
>> }
>>
>> print apple('apple'), "\n";
>> print apple('berry'), "\n";
>>
>> exit;
>>
>>
>> But problem is that I do not know what is return value in the finally
>> block... :(
> 
> Don't do that then.
> 
> sub apple {
>     my $rv;
> 
>     try {{

OP - take a look at $_[0] here.. it's not what you think it is.

>         $rv = 'fruit', last if $_[0] eq 'apple';
>         $rv = 'possibly a fruit';
>     }}
>     finally {
>         print 'finally at apple(): $rv';
           print "finally at apple(): $rv";

Or depending on the use, simply return $rv;

           return $rv;

>     }
> }
> 
> Note the {{ }} on the try: one set delimits the try block, the second
> set creates a bare block so that last works.


------------------------------

Date: 14 Nov 2006 08:51:37 -0800
From: edwells@statestreet.com
Subject: running dos commands from perl script
Message-Id: <1163523097.119641.250510@b28g2000cwb.googlegroups.com>

My apologies for posting on this over hashed subject, but I need to set
up environment variables in DOS(XP) then execute a program using the
vars. I'm not having any problem with the individual commands, but
can't get the executable to to use the previously set variables.
Here's my code:

!/usr/bin/perl -w

system 'set var_1';
system 'set var_2';
system ' c:\progs~1\runexe.exe jobname >c:\xx.xx';



------------------------------

Date: Tue, 14 Nov 2006 12:07:48 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: running dos commands from perl script
Message-Id: <m2velihs7v.fsf@Sherm-Pendleys-Computer.local>

edwells@statestreet.com writes:

> My apologies for posting on this over hashed subject, but I need to set
> up environment variables in DOS(XP) then execute a program using the
> vars. I'm not having any problem with the individual commands, but
> can't get the executable to to use the previously set variables.
> Here's my code:
>
> !/usr/bin/perl -w
>
> system 'set var_1';
> system 'set var_2';
> system ' c:\progs~1\runexe.exe jobname >c:\xx.xx';

Each call to system() launches a new child task, each of which has its own
set of environment variables that are unrelated to the previous child task.

But, a child's environment variables are inherited from the parent. So what
you could do is manipulate %ENV (perldoc perlvar) in your parent script
instead of using system() to run "set" commands. Something like this:

#!/usr/bin/perl

use warnings; # Preferable over -w
use strict;   # You forgot that...

# obviously just example values and command...
$ENV{'var_1'} = 'val_1';
$ENV{'var_2'} = 'val_2';
system 'do stuff';

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Tue, 14 Nov 2006 19:56:55 +0100
From: Richard <critterstown@googlemail.com>
Subject: Re: running dos commands from perl script
Message-Id: <ejd3hn$ps7$1@online.de>

edwells@statestreet.com schrieb:
> My apologies for posting on this over hashed subject, but I need to set
> up environment variables in DOS(XP) then execute a program using the
> vars. I'm not having any problem with the individual commands, but
> can't get the executable to to use the previously set variables.
> Here's my code:
> 
> !/usr/bin/perl -w
> 
> system 'set var_1';
> system 'set var_2';
> system ' c:\progs~1\runexe.exe jobname >c:\xx.xx';
> 
system 'set var_1 && set var_2 && c:\progs\runexe.exe jobname c:\xx.xx'



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9967
***************************************


home help back first fref pref prev next nref lref last post