[24443] in Perl-Users-Digest
Perl-Users Digest, Issue: 6626 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 29 21:05:54 2004
Date: Sat, 29 May 2004 18:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 29 May 2004 Volume: 10 Number: 6626
Today's topics:
Re: Another Dereference Post by me <mikeflan@earthlink.net>
Re: Another Dereference Post by me <mikeflan@earthlink.net>
Re: Another Dereference Post by me <mikeflan@earthlink.net>
Re: Another Dereference Post by me <mikeflan@earthlink.net>
Re: Another Dereference Post by me <uri@stemsystems.com>
Re: Another Dereference Post by me <ittyspam@yahoo.com>
Array in a hash question? (Jamie Smyth)
Re: Array in a hash question? <matthew.garrish@sympatico.ca>
Effective perl function to remove one element from arra (josh)
Re: Login to MS Exchange to send e-mail <grante@visi.com>
Re: Login to MS Exchange to send e-mail <usenet@rudn.com>
Re: Login to MS Exchange to send e-mail <Petri_member@newsguy.com>
Re: On "for (@foo)" <dha@panix2.panix.com>
Re: On "for (@foo)" <ittyspam@yahoo.com>
Re: Perl to c <noreply@nowhere.com>
Print a formatted array (Jamie Smyth)
Re: Setting ENV varibles by calling a shell script with <dmcbride@naboo.to.org.no.spam.for.me>
strange behavior <perl@my-header.org>
Re: strange behavior <wherrera@lynxview.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 29 May 2004 20:15:49 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Another Dereference Post by me
Message-Id: <40B8EF6D.9C665662@earthlink.net>
Uri Guttman wrote:
> what does adding COL do?
It just stands for Column.
> that is a very odd indent for the close }. try putting it under the line
> that opened it. this is the 'approved' perl indent style and most
> hackers use it. it is also the gnu style.
I can't believe I didn't see that. Thanks.
>
>
> MF> print "\n";
>
> MF> my @sorted =
> MF> map $_->[0],
> MF> sort { $b->[1] cmp $a->[1] }
> MF> map [$_, /(.*)/ ? $1 : die "$_"],
>
> @data is a array of anon arrays. so map will set $_ to an array ref each
> time. and /(.*)/ is matching against that array ref (NOT the array data)
> which is meaningless.
>
> MF> @data;
>
> good idea would be to describe the sort operation.
>
> MF> #print the sorted list
> MF> foreach my $line (@sorted) {
> MF> print join("|" => @$line);
>
> where is the useful trailing newline?
>
Thanks for all the comments. I'm still digesting this.
Mike
------------------------------
Date: Sat, 29 May 2004 20:19:44 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Another Dereference Post by me
Message-Id: <40B8F057.21C2AF15@earthlink.net>
Peter Scott wrote:
> I am having a hard time guessing what this type of sorting of
> two-dimensional data is buying you. You'll end up with a list
> sorted by latitude but with longitude all over the place.
> I can only think of marginally useful esoteric purposes for that
> so far.
It just simplifies the next step in the process, which is to
open the text file in Excel, (sort by lat/long until I get this code
to work), delete the duplicates, and then do a bunch of other
stuff. So I just want the duplicates (exactly identical lat/longs)
together. Unfortunately, I can't write a program that can
decide as well as I can which duplicate record to delete, and
which to keep.
Mike
------------------------------
Date: Sat, 29 May 2004 22:48:26 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Another Dereference Post by me
Message-Id: <40B9132D.992769DB@earthlink.net>
Uri Guttman wrote:
> @data is a array of anon arrays. so map will set $_ to an array ref each
> time. and /(.*)/ is matching against that array ref (NOT the array data)
> which is meaningless.
>
> MF> @data;
>
> good idea would be to describe the sort operation.
>
Thanks for all the tips. I never did understand the double
map, but almost certainly will someday. In fact the next
PerlMonger meeting I attend will cover that subject -
again!
I stepped back to a "slower" approach, or at least reportedly
slower for large data sets. My data sets are only 500 - 1000
lines, so the "slow" approach goes quite fast for my needs.
The code below does what I needed.
Every once in a while I think that Perl needs more structure,
but then I slap myself and realize that somebody like me
needs every bit of the flexibility that Perl has.
Mike
use strict;
use warnings;
use constant COL1 => 0;
use constant COL2 => 1;
use constant COL3 => 2;
use constant COL4 => 3;
use constant COL5 => 4;
use constant COL6 => 5;
my @data = map [ split /\|/, $_, 5 ], <DATA>;
# Identify duplicate lat/long's
my %saw;
foreach my $line (@data) {
print "$line->[ COL1 ]\n";
if ($saw{ $line->[ COL5 ] }++) {
print "found dup\n";
$line->[ COL1 ] .= "+++++";
}
}
print "\n";
my @sorted = sort { $a->[ COL5 ] cmp $b->[ COL5 ] } @data;
foreach my $line (@sorted) {
print join("|" => @$line);
}
__DATA__
Camdenton Medical Center|Green Bay Terrace|Camden|hospital|380141N0924604W|MO
Carpenter Memorial State Wildlife Area|Boylers
Mill|Morgan|park|381715N0930417W|MO|||||0
Mansfield Forest State Wildlife Management Area|Lake
Ozark|Camden|park|380823N0924256W|MO|||||0
Brockman Island|Bagnell|Miller|area|380141N0924604W|MO
Hawaiian Island|Lake Ozark|Miller|island|381317N0924115W|MO|||||0
------------------------------
Date: Sat, 29 May 2004 22:49:29 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Another Dereference Post by me
Message-Id: <40B9136D.1CCB346D@earthlink.net>
Paul Lalli wrote:
> What the hey is this? Looking at your (bottom) map statement, foreach
> element of @data, you're creating an anonymous array reference. The first
> element of this array is the current element of @data. The second element
> of this array is the grouped subpattern of /(.*)/ if that pattern match
> succeeded. There are a number of very bizzare issues here:
>
> 1) /(.*)/ cannot fail. Ever. Why are you adding code to check for this?
The original code had /d+ and used the <=> operator. I changed it
to a VERY general format, because I couldn't find a way to simply
get rid of the regex part.
>
> 2) .* will match as much of the string as it can. Since there are no
> newlines in your data, and .* isn't being anchored to any other part of a
> match, $1 will therefore contain the entire string - that is, it will be
> identical to $_
Yeah, I think I realized that. At that point I was just trying
to get ANY sort to work for me. I was in learning mode :-)
> 3) So now you've created a reference to an array containing [$_, $_].
> Why? It looks like you've decided to use a Schwartzian transform without
> understanding why you'd do such a thing.
You hit the nail on the head there. In fact I got that code from a
5/21/04 post by . . . . . Randal L. Schwartz :-)
> In your script, @data is an array of array references, each containing at
> most 5 elements. You said you want to sort by the fifth column. Looking
> at your data, however, it looks like there are some lines that do not have
> a fifth column. What do you want to do with those rows?
They all have at least 5 columns, so I think I am OK there.
> Ignoring that detail for the moment, the sort you say you want to perform
> is far easier than you tried to make it:
>
> my @sorted = sort { $a->[4] cmp $b->[4] } @data;
Hey, I figured this out on my own (sort of), before I read your
post here. That does work great. And simple enough that
I may be able to remember it.
> This works because within the sort subroutine, $a and $b will be two
> elements of @data. Each element of @data is an array reference. To get
> at the elements of an array when you have it's reference, you can
> dereference it using the arrow operator as I've done above.
>
> For more info on referencing and dereferencing, consult perldoc perlreftut
>
> If I haven't understood your issue, consider making your goal more
> explicit.
>
> Paul Lalli
>
Thanks for all the help. That is exactly the help I needed.
I can't thank you enough for taking the time to teach me.
I need to work with these anon things much much more.
Mike
------------------------------
Date: Sat, 29 May 2004 23:12:24 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Another Dereference Post by me
Message-Id: <x7brk6bzfs.fsf@mail.sysarch.com>
>>>>> "MF" == Mike Flannigan <mikeflan@earthlink.net> writes:
MF> Uri Guttman wrote:
>> good idea would be to describe the sort operation.
MF> Thanks for all the tips. I never did understand the double
MF> map, but almost certainly will someday. In fact the next
MF> PerlMonger meeting I attend will cover that subject -
MF> again!
MF> I stepped back to a "slower" approach, or at least reportedly
MF> slower for large data sets. My data sets are only 500 - 1000
MF> lines, so the "slow" approach goes quite fast for my needs.
MF> The code below does what I needed.
MF> Every once in a while I think that Perl needs more structure,
MF> but then I slap myself and realize that somebody like me
MF> needs every bit of the flexibility that Perl has.
then use the Sort::Maker module i have been mentioning here. it is in
beta release (see other recent sort threads where i give the url).
i am not sure how it will work with constants like that at the
moment. as long as you pass in a string for the code extraction it
should be fine. '$_->' . COL5 should work ok.
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: Sat, 29 May 2004 20:04:32 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Another Dereference Post by me
Message-Id: <20040529195159.J18263@dishwasher.cs.rpi.edu>
On Sat, 29 May 2004, Mike Flannigan wrote:
> Paul Lalli wrote:
>
> > 3) So now you've created a reference to an array containing [$_, $_].
> > Why? It looks like you've decided to use a Schwartzian transform without
> > understanding why you'd do such a thing.
>
> You hit the nail on the head there. In fact I got that code from a
> 5/21/04 post by . . . . . Randal L. Schwartz :-)
Mr. Schwartz's technique, which has been named for him, is generally used
when one wishes to sort a list of items using a costly (computationally
heavy) calculation. For example, sorting a list of files by their
modification times in this manner:
@sorted = sort { -M $a <=> -M $b } @files;
would be VERY costly, because of the large cost of performing a stat() on
each file many many times. (In the worst case scenario, each file's
modification time would have to be computed again for every other file in
the list). Using the Schwartzian transform, each file's modification time
is computed only once, and these values are stored in a temporary
anonymous array.
If you don't need to do anything that complicated, you don't want to be
using that algorithm.
> > Ignoring that detail for the moment, the sort you say you want to perform
> > is far easier than you tried to make it:
> >
> > my @sorted = sort { $a->[4] cmp $b->[4] } @data;
>
> Hey, I figured this out on my own (sort of), before I read your
> post here. That does work great. And simple enough that
> I may be able to remember it.
If you have Mr. Schwartz's excellent book "Learning Perl", read the
chapter on sorting (Chapter 15, I believe). If you don't have it - buy
it! :-)
> Thanks for all the help. That is exactly the help I needed.
> I can't thank you enough for taking the time to teach me.
>
> I need to work with these anon things much much more.
read the following documentations:
perldoc perlreftut -- a brief tutorial introducing you to references
perldoc perllol -- "Lists Of Lists", showing you how to create and use
multidimensional arrays. (In perl, these are constructed using anonymous
array references)
perldoc perldsc -- "Data Structures Cookbook". This builds on "lists of
lists", showing you how to construct arrays of hashes, hashes of arrays,
hashes of hashes, arrays of hashes of arrays of arrays of hashes of ...
(you get the idea).
Once you've read (and understood) all those, delve into
perldoc perlref
for all the gory details of references.
Glad you found my post helpful.
Paul Lalli
------------------------------
Date: 29 May 2004 15:57:36 -0700
From: jamiesmyth_uni@yahoo.ca (Jamie Smyth)
Subject: Array in a hash question?
Message-Id: <120533fa.0405291457.573803fb@posting.google.com>
I have a hash defined as,
my %data = (
'wn_l' => $wn_l, 'wn_u' => $wn_u, 'wn_d' => $wn_d,
'npts' => $#spc+1, 'spc' => [@spc], 'label' => $label,
);
and I would like to extract the data in the @spc array. I tried,
my @spc = %data{'spc'};
and
my $spc = %data{'spc'};
but this results in the array being created directly in @spc[0]. I
ended up using:
my $d = $data{'spc'};
my @data = ();
push @data, @$d;
which gives me a 1dimensional array @data that I can use... the
problem is that I don't really know why this works and it looks a
little weird. Can someone explain?
Thanks.
------------------------------
Date: Sat, 29 May 2004 19:06:17 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Array in a hash question?
Message-Id: <EH8uc.51244$sr3.1486929@news20.bellglobal.com>
"Jamie Smyth" <jamiesmyth_uni@yahoo.ca> wrote in message
news:120533fa.0405291457.573803fb@posting.google.com...
> I have a hash defined as,
>
> my %data = (
> 'wn_l' => $wn_l, 'wn_u' => $wn_u, 'wn_d' => $wn_d,
> 'npts' => $#spc+1, 'spc' => [@spc], 'label' => $label,
> );
>
> and I would like to extract the data in the @spc array. I tried,
>
> my @spc = %data{'spc'};
>
The value for key spc is a reference to an array (hash values are always
scalars). In order to access the array, you need to dereference the
reference:
my @array = @{ $data{'spc'} };
Matt
------------------------------
Date: 29 May 2004 17:44:08 -0700
From: josh.kuo@prioritynetworks.net (josh)
Subject: Effective perl function to remove one element from array?
Message-Id: <66001607.0405291644.3993e158@posting.google.com>
Hi all:
I am trying to find out the most efficient way to remove an element
from an array, and have the array size shrink by one.
pop, push, and splice won't work too well for me, I am trying to
remove an element that could be in any position.
Here is my current implementation (may not actually compile, just a
example)
<psuedo perl code>
# this array is purposely unsorted
@array = ['bob', 'alice', 'david', 'christy', 'edward', 'henry',
'frank'];
@array = removeFromArray ( @array, "edward" );
sub removeFromArray {
@array = $_[0];
$name = $_[1];
for ( $i = 0; $i < @$array; $i++ ) {
if ( $array[$i] eq $name ) {
unset $array[$i];
}
}
}
</psuedo perl code>
As you can see, this is not exactly the most efficient way of removing
an element as the size of my array grows. And especially when I run
this in a nested loop, say, when I want to compare two arrays and
remove the differences, it will result in a close to BigO(n^2)
efficiency.
Is there a faster, more efficient way to remove an element from an
array (and preferrably not BigO(n) )?
Will it help if I am performinig this on an already sorted array? Then
I can perhaps use some sort of binary search function to find the item
I am looking for?
------------------------------
Date: 29 May 2004 18:56:45 GMT
From: Grant Edwards <grante@visi.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <slrncbhn7d.ti3.grante@grante.rivatek.com>
On 2004-05-29, Joe <joe@jretrading.com> wrote:
>>> I understood the SMTP and POP3 description. But it doesn't
>>> answer my question. I am asking how to login like MS Outlook,
>>> not by POP3 or SMTP.
>>
>>You can't. Outlook uses a proprietary, undocumented protocol
>>to talk to Exchange server. The only way to send mail w/o
>>using SMTP is to run you application under Windows and use the
>>COM interface to Outlook and send mail using Outlook itself.
>
> The protocol is called MAPI. Search for this on the Net to get a feel
> for the ease of interfacing with it.
MAPI (Messaging Application Program Interface) is the library
API rather than the protocol:
http://www.outlookcode.com/d/mapi.htm
--
Grant Edwards grante Yow! It don't mean a
at THING if you ain't got
visi.com that SWING!!
------------------------------
Date: Sat, 29 May 2004 17:30:53 -0400
From: Jeff Breitner <usenet@rudn.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <10bi052h91jb2b8@corp.supernews.com>
Y W Wong wrote:
> I understood the SMTP and POP3 description.
> But it doesn't answer my question.
> I am asking how to login like MS Outlook, not by POP3 or SMTP.
> Hope that someone know what I am asking for.
>
You can log in for mail retrieval using IMAP (provided it is enabled).
You will not see any of your contact or calendaring data however since
this isn't MAPI.
I do not know of any compatible MAPI clients.
--
WWJD? JWRTFM
Rot13 for email address: yvfgf @ ehqa.pbz
------------------------------
Date: 29 May 2004 15:11:09 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <c9b1pt0rav@drn.newsguy.com>
In article <c9adch$1sjv$1@news.hgc.com.hk>, Y W Wong says...
>>>> Ask your exchange admin to start the SMTP-, and IMAP- or
>>>> POP3-connectors on the Exchange Server. Then use the usual
>>>> mail-modules available from CPAN.
>>> I just want to act as a simple script type MS Outlook to
>>> send text mail. Anyone know how ?
>> Yes. You've just been told how. What part of the answer
>> didn't you understand?
> I understood the SMTP and POP3 description.
> But it doesn't answer my question.
> I am asking how to login like MS Outlook, not by POP3 or SMTP.
> Hope that someone know what I am asking for.
Do you know, yourself?
Use POP3 or IMAP to login to your exchange mailbox, just like Outlook does.
What's the problem?
Actually, you probably don't even have to login at all, since you claim you only
want to send email, and SMTP authentication is not on by default in Exchange
Server.
use Net::SMTP; # Or anyone of the numerous free email modules on CPAN.
Petri
------------------------------
Date: Sat, 29 May 2004 18:12:13 +0000 (UTC)
From: "David H. Adler" <dha@panix2.panix.com>
Subject: Re: On "for (@foo)"
Message-Id: <slrncbhkjt.fn5.dha@panix2.panix.com>
On 2004-05-28, Paul Lalli <ittyspam@yahoo.com> wrote:
> On Fri, 28 May 2004, David H. Adler wrote:
>
>> On 2004-05-28, Ben Morrow <usenet@morrow.me.uk> wrote:
>>
>> > You never need C-style loops:
>> >
>> > for my $i (0..$#X) {
>> > $X[$i] = 0;
>> > }
>>
>> "Never"?
>>
>> How about:
>>
>> for ($i = 20; $i > 0; $i--) {
>> do_stuff_with($i);
>> }
>>
>
> for my $i (reverse (1..20)){
> do_stuff_with($i);
> }
>
>> (and, although I'm sure someone will come up with a way of avoiding the
>> c-style loop there, I'm not sure it'll be more readable)
>
>
> I disagree. <shrug>
Ok, here you got me. I should have stuck with my original thought
of using $i - 3 instad of $i-- ...
Really, my disagreement was with the, IMO, extreme "never". I'd be
happy with "extremely rarely". :-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
SURF MUSIC makes EVERYTHING better! - Tom Servo
------------------------------
Date: Sat, 29 May 2004 16:27:38 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: On "for (@foo)"
Message-Id: <20040529162152.R18263@dishwasher.cs.rpi.edu>
On Sat, 29 May 2004, David H. Adler wrote:
> On 2004-05-28, Paul Lalli <ittyspam@yahoo.com> wrote:
> > On Fri, 28 May 2004, David H. Adler wrote:
> >
> >> How about:
> >>
> >> for ($i = 20; $i > 0; $i--) {
> >> do_stuff_with($i);
> >> }
> >>
> >
> > for my $i (reverse (1..20)){
> > do_stuff_with($i);
> > }
> >
>
> Ok, here you got me. I should have stuck with my original thought
> of using $i - 3 instad of $i-- ...
for my $i (grep { ($_ + 1) % 3 == 0 } reverse (1..20) ) {
do_stuff_with($i);
}
>
> Really, my disagreement was with the, IMO, extreme "never". I'd be
> happy with "extremely rarely". :-)
At this point, I'm mostly joking. I would never actually write code like
the above. I'm just not convinced there's any variation of a C-style for
loop that cannot be emulated with a Perl-style foreach loop.
Paul Lalli
------------------------------
Date: Sat, 29 May 2004 23:43:56 GMT
From: Shailesh Humbad <noreply@nowhere.com>
Subject: Re: Perl to c
Message-Id: <0f9uc.4859$DG4.231@fe2.columbus.rr.com>
Profetas wrote:
> Is there any perl to c converter?
>
> Thanks
>
Not that I know of. But, you can convert Perl to EXE.
http://www.indigostar.com/perl2exe.htm
------------------------------
Date: 29 May 2004 15:51:14 -0700
From: jamiesmyth_uni@yahoo.ca (Jamie Smyth)
Subject: Print a formatted array
Message-Id: <120533fa.0405291451.6e3f3935@posting.google.com>
I'm having some trouble printing an array in Perl. The array is very
long and must be read in by some archaic FORTRAN code so the spacing
needs to be exact. For those that speak FORTRAN, the format is
basically '(5(F16.10))'.
In perl I have:
105 my $i;
106 for ($i=0; $i<(scalar(@data)); $i++) {
107 my $s = int($i*6);
108 #print "$s $e \n";
109 $fh->printf("%10.6f %10.6f %10.6f %10.6f %10.6f\n",
110 $data[$s], $data[$s+1], $data[$s+2], $data[$s+3],
$data[$s+4]);
111 }
In addition to being rather awful looking and slow, the above code
pads a partially full, last line with zero values if the number of
elements in the array is not divisible by 5.
Is there an easier way?
Thanks.
------------------------------
Date: Sun, 30 May 2004 00:18:03 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: Setting ENV varibles by calling a shell script within a perl program
Message-Id: <%K9uc.621915$Ig.482226@pd7tw2no>
Tad McClellan wrote:
> ad <as@no-span.org> wrote:
>>
>> I need to make some system calls to other programs from a perl program
>> and those programs that are being called have some environment
>> variable dependencies that are set by a shell script program. So I
>> have to call this shell script to set up (export bunch of variables)
> ^^^^^^^
>> environment variables so that the other program that I call can run
>> fine.
>
>
> No you don't.
Sometimes ... you do.
e.g., I have a program "P" which can be installed anywhere. There is a
script which may call a script which may call a script that sets
"P_HOME". That script, or a symlink to it, is in a well-known place,
even if that is relative to where my perl script is located.
Much easier, safer, and maintainable would be to have my perl script
use the shell to interpret the script that sets the environment. This
way, when the sysadmin moves P to a new location, s/he only must
maintain a single point of contact (the shell script), which s/he is
very likely to remember to do, but would be very unlikely to remember
to update a perl script to have the same ENV entry.
> You can set env vars in Perl via the %ENV hash.
Yes - but that's not always useful.
> Any external processes (child) you start will inherit their env from
> the Perl program (parent).
>
>
>> If all possible, I am trying to avoid writing another shell program
>> that call the other shell program prior to my perl program since I
>> have lots of variable combination that my perl program can run with
>> and do not want to have all the variable validated with this extra
>> shell program so that it can call my perl program.
>
>
> If you want access to those env vars in your Perl program, then
> wrapping it in a sh program is what you should do.
>
> I don't think I understand what your objection to that approach is.
>
> Why is that not a good solution?
An extra layer of dependancy? In this world, we have A.sh calling
A.pl. We then need to ensure that no one calls A.pl except through
A.sh. This may be trivial for a new program, but if it's an existing
perl script which is being called by numerous automated processes, that
may not be as good.
>> #system(". ./myShell.sh"); # Tried both
>
>
> If you just want to launch programs that make use of those env vars,
> and don't need them in your Perl program, then just set them in
> the same (sub) process:
>
>
> system '. ./myShell.sh; other_prog';
Yes - I think this is the easiest solution that completely fulfills the
OPs requests. The downside is that if "other_prog" has shell
metacharacters in the commandline, or anything else the shell may take
funny, it'll be a blast getting around it.
Another solution, which is kinda ugly, is to do something like this:
my @lines = `. myShell.sh; env`;
Then, parse each line, splitting on '=', and putting them into your
%ENV hash:
foreach my $line (@lines)
{
/([^=]+)=(.*)/ and $ENV{$1} = $2;
}
This may have some funny side effects - if myShell.sh sets some
variable that Perl ends up using, what happens depends on whether the
perl module in question has already read that environment variable or
not.
Here, then, you can go back to using the multi-arg version of system to
avoid the shell's reinterpretation of your commands.
------------------------------
Date: Sat, 29 May 2004 20:38:12 +0200
From: Matija Papec <perl@my-header.org>
Subject: strange behavior
Message-Id: <9hkhb0tamfeve3pohmjclqfv3tjn8vt5f6@4ax.com>
I thought that output should be the same for all four lines but they differ.
Am I running buggy perl? (5.8.0)
use strict;
use warnings;
for my $i (0..3) {
my $row=2;
my $tmp = join ' ', map { $_ += 5*$row } 0 .. 4;
print "$row - $tmp\n";
}
---------- Capture Output ----------
2 - 10 11 12 13 14
2 - 20 21 22 23 24
2 - 30 31 32 33 34
2 - 40 41 42 43 44
--
Matija
------------------------------
Date: Sat, 29 May 2004 14:56:43 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: strange behavior
Message-Id: <A7adneXVp4KGZCXdRVn-ig@adelphia.com>
Matija Papec wrote:
> I thought that output should be the same for all four lines but they differ.
> Am I running buggy perl? (5.8.0)
>
>
> use strict;
> use warnings;
>
> for my $i (0..3) {
> my $row=2;
> my $tmp = join ' ', map { $_ += 5*$row } 0 .. 4;
> print "$row - $tmp\n";
> }
>
> ---------- Capture Output ----------
> 2 - 10 11 12 13 14
> 2 - 20 21 22 23 24
> 2 - 30 31 32 33 34
> 2 - 40 41 42 43 44
>
>
>
Yeah, the 0 .. 4 array is getting clobbered in the map function. (Don't
do that? :) )
Try:
============================
use strict;
use warnings;
print "\nMode 1\n";
for my $i (0..3) {
my $row=2;
my $tmp = join ' ', map { $_ += 5*$row } 0 .. 4;
print "$row - $tmp\n";
}
print "\nMode 2\n";
for my $j (0..3) {
$_ = 0;
my $row=2;
my $tmp = join ' ', map { 5*$row + $_ } 0 .. 4;
print "$row - $tmp\n";
}
print "\nMode 3\n";
for my $i (0..3) {
my @a = (0 .. 4);
my $row=2;
my $tmp = join ' ', map { $_ += 5*$row } @a;
print "$row - $tmp\n";
}
==============================
------------------------------
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 6626
***************************************