[18184] in Perl-Users-Digest
Perl-Users Digest, Issue: 352 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 25 00:05:31 2001
Date: Sat, 24 Feb 2001 21:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983077507-v10-i352@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 24 Feb 2001 Volume: 10 Number: 352
Today's topics:
#!/usr/local/bin/perl -w || /usr/bin/perl -w (Michael Wang)
Re: #!/usr/local/bin/perl -w || /usr/bin/perl -w <godzilla@stomp.stomp.tokyo>
Re: 2 keys for one hash. <bwalton@rochester.rr.com>
Re: 2 keys for one hash. (Logan Shaw)
Re: 2 keys for one hash. <bwalton@rochester.rr.com>
Re: 2 keys for one hash. (Martien Verbruggen)
Re: 2 keys for one hash. egwong@netcom.com
Re: about software installation on Solaris (Martien Verbruggen)
Re: Delete (Martien Verbruggen)
Re: How can I detect if program is run by cron? (Logan Shaw)
Re: How can I detect if program is run by cron? (Martien Verbruggen)
Re: Is an array of hashes the best way to do this? nobull@mail.com
regexp question <mike@mannacabana.com>
Re: server question nobull@mail.com
Simple(?) server process <jandkporter@mediaone.net>
Re: Simple(?) server process (Logan Shaw)
Re: Simple(?) server process <jandkporter@mediaone.net>
Re: Simple(?) server process (Logan Shaw)
Re: SMTP server (David Efflandt)
Re: splice question (Martien Verbruggen)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 25 Feb 2001 03:42:16 GMT
From: mwang@mindspring.com (Michael Wang)
Subject: #!/usr/local/bin/perl -w || /usr/bin/perl -w
Message-Id: <sa%l6.9021$JK2.676690@news.uswest.net>
On Solaris 8, an old version of Perl is installed in
/usr/bin/perl, and a new version in /usr/local/bin/perl.
I want to use the newer version if it is there, otherwise
I want to use the older version. How do I convey the idea
in #! line?
#!/usr/bin/env perl
isn't an option as it depends on the user's PATH, which is not a good
idea for non-interactive use. For the script maybe run on cron or other
schedulers. It is better to make the script self sufficient. That is,
it should be able to run with "env -i ./script".
I did read the Perl book (3rd ed) page 488, but no solution is provided
there.
------------------------------
Date: Sat, 24 Feb 2001 20:17:49 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: #!/usr/local/bin/perl -w || /usr/bin/perl -w
Message-Id: <3A98876D.894D6738@stomp.stomp.tokyo>
Michael Wang wrote:
(snippage)
> On Solaris 8, an old version of Perl is installed in
> /usr/bin/perl, and a new version in /usr/local/bin/perl.
> I want to use the newer version if it is there, otherwise
> I want to use the older version.
It is not my intent to be rude but your statements
are oxymoronic. Initially you state two versions
of Perl are installed; old and new.
Next you state you want to use the newer version,
"...if it is there."
Are you unsure if a newer version is installed or not?
How do I convey the idea
> in #! line?
> #!/usr/bin/env perl
If you give a Perl script a choice between two
versions of Perl, what criteria will your script
use to decide which to use?
"use older version OR use newer version"
How would a script decide?
It appears you have scripts floating about, perhaps
lacking a 'use this version of Perl' requirement.
So how will you shunt a script to one version or
the other version? Again, what criteria will you
establish to do this? System read a script before
excution to decide what version would be best for
a given style of programming?
Give some thought to the difficulties involved
in informing users their scripts need to be
modified, to work correctly. This surely will
create a lot of questions, which you will
have to answer, if not solve personally.
Use good logic and direct all scripts to your
newest version of Perl. All newer versions of
Perl support Perl as far back as version 4,
perhaps even older, with very few problems.
It is exceptionally illogical to branch off
in one direction or the other without strict
criteria for this; nearly impossible criteria.
"if this version, do this.
elsif this version, do this.
else flip a coin or do nothing."
It is logical to internally redirect scripts
to one version of Perl, regardless of path.
Leave well enough alone or, simply internally
direct all scripts to your new Perl version.
Godzilla!
--
------------------------------
Date: Sun, 25 Feb 2001 02:13:36 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 2 keys for one hash.
Message-Id: <3A986AB9.747932E3@rochester.rr.com>
"Kauser Ali Karim ;)" wrote:
...
> Is it possible to have a hash that has two key values.
> If so, I'd appreciate an example.
...
> Kauser
...
%hash=('one'=>1,'two'=>2);
--
Bob Walton
------------------------------
Date: 24 Feb 2001 20:26:06 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: 2 keys for one hash.
Message-Id: <979qfu$fq4$1@boomer.cs.utexas.edu>
In article <3A986AB9.747932E3@rochester.rr.com>,
Bob Walton <bwalton@rochester.rr.com> wrote:
>"Kauser Ali Karim ;)" wrote:
>> Is it possible to have a hash that has two key values.
>> If so, I'd appreciate an example.
>%hash=('one'=>1,'two'=>2);
Gee, I think the original poster expected the question to be
interpreted as, "Is it possible to have a hash that has two keys for
each value?"
--
my your his her our their *its*
I'm you're he's she's we're they're *it's*
------------------------------
Date: Sun, 25 Feb 2001 03:02:08 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 2 keys for one hash.
Message-Id: <3A987619.B78B355@rochester.rr.com>
Logan Shaw wrote:
>
> In article <3A986AB9.747932E3@rochester.rr.com>,
> Bob Walton <bwalton@rochester.rr.com> wrote:
> >"Kauser Ali Karim ;)" wrote:
> >> Is it possible to have a hash that has two key values.
> >> If so, I'd appreciate an example.
>
> >%hash=('one'=>1,'two'=>2);
>
> Gee, I think the original poster expected the question to be
> interpreted as, "Is it possible to have a hash that has two keys for
> each value?"
> --
Oh. Like: %hash=('one'=>1,'two'=>1); :-)
--
Bob Walton
------------------------------
Date: Sun, 25 Feb 2001 13:56:35 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: 2 keys for one hash.
Message-Id: <slrn99gt33.pen.mgjv@martien.heliotrope.home>
On Sun, 25 Feb 2001 01:03:23 GMT,
Kauser Ali Karim ;) <g9karkav@cdf.toronto.edu> wrote:
>
> Is it possible to have a hash that has two key values.
Not directly, but there are a few ways of solving this problem
First of all, you can concatenate your two keys to form one string, and
use that for the hash key. While concatenating, it would be a good idea
to insert a character between the two that never appears as part of your
regular strings. You can also have Perl do this automatically for you,
using multidimensional array emulation (see perlvar, under the variable
$;).
my $key = join $join_char, $key1, $key2;
$foo{$key} = $value;
# or, as a multidimensional emulation:
$foo{$key1,$key2} = $value;
You can also just store hash references as the value of your hash
elements, and create a hash of hashes. They are quite substantially
discussed in the perlref, perllol, perldsc and perlreftut documentation.
If you need to iterate over all elements, you need to do some extra
work, but you also need to do that in the previous example. Since you
don't specify that you need to do that, I won't talk any more about it,
and let you read the documentation first.
$foo{$key1}{$key2} = $value;
Martien
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: 25 Feb 2001 03:27:22 GMT
From: egwong@netcom.com
Subject: Re: 2 keys for one hash.
Message-Id: <979u2q$17ve$1@newssvr05-en0.news.prodigy.com>
Logan Shaw <logan@cs.utexas.edu> wrote:
> In article <3A986AB9.747932E3@rochester.rr.com>,
> Bob Walton <bwalton@rochester.rr.com> wrote:
>>"Kauser Ali Karim ;)" wrote:
>>> Is it possible to have a hash that has two key values.
>>> If so, I'd appreciate an example.
>
>>%hash=('one'=>1,'two'=>2);
>
> Gee, I think the original poster expected the question to be
> interpreted as, "Is it possible to have a hash that has two keys for
> each value?"
For a moment, I thought the original poster was asking if it were
possible to have two keys point to the same value, a la
my $var = 1;
my %hash = ( one => \$var , two => \$var );
print ${$hash{one}}, " ", ${$hash{two}}, "\n";
${$hash{one}}++;
print ${$hash{one}}, " ", ${$hash{two}}, "\n";
${$hash{two}}++;
print ${$hash{one}}, " ", ${$hash{two}}, "\n";
*shrug*
------------------------------
Date: Sun, 25 Feb 2001 14:04:34 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: about software installation on Solaris
Message-Id: <slrn99gti2.pen.mgjv@martien.heliotrope.home>
On Sun, 25 Feb 2001 01:37:36 GMT,
Michael Wang <mwang@mindspring.com> wrote:
>>> >Extra software you install (on any SVR4 unix) should go in /opt - that's
>>> >exactly what it's for. You should make sure /opt is a separate filesystem
>>> >with enough space free for all the extra unbundled software you want to
>>> >add to the system.
>
> I do know /opt, but I find it troublesome to have
> /opt/this and /opt/that, and the PATH becomes ridiculously
> long and unmanageable.
I have no problem with it. I use it on almost all platforms, regardless
of whether it's common there or not.
> /usr/local area is nice except name clashes.
Create symlinks from /usr/local/bin to the appropriate /opt
installation, and for most users it never even becomes visible. The
people who need to have more of this stuff in their path, can simply
include it.
You can also help your users, and adapt your system wide login scripts,
maybe protected with -d checks.
Installation in /usr/local can be troublesome if you need to keep more
than one version around, and the software doesn't allow you to do this.
However, Perl can have multiple versions installed in /usr/local, at the
same time.
> I also find the Perl module installation approach is troublesome.
> They always want to append something to a common file. This is hard to
> make a Solaris package for the module (imagine how to add and remove).
> They should just use their own files for each module, and then a program
> (something like catman) to rebuild the common file any at time.
To each their own. You're meant to use the Perl mechanisms to install
Perl modules. If you don't want to, then it's up to you to make it work.
Of course, there's nothing to stop you from creating a package that
simply takes the module's tar file, and runs make install in the
unpacked directory. You could also run make, up to test, create a
package from the resulting tree, and then run make install on the
target machine.
I wouldn't do either of these two, though. I'd just not append the
installation information to the pod file. There's no need for it. It's
more or less just a log file. If you manage all your modules as Solaris
packages, why would you need a separate log for it?
I maintain several Perl installations, on several versions of Solaris,
and never had any problems finding a good way to do things. But then, I
don't really feel that everything should be a package. A simple source
installation on one machine, and rdist go a long way.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Sun, 25 Feb 2001 14:24:48 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Delete
Message-Id: <slrn99guo0.pen.mgjv@martien.heliotrope.home>
On 25 Feb 2001 02:08:11 +0100,
y_jim Y <y_jim54@hotmail.com> wrote:
> Hi,
>
> In perl how do I in a text:
First of all, you will _have_ to decide what you consider to be a word.
Let's just take the simple assumption that your words consist of digits
letters and an underscore, so that \w neatly matches a word character.
With the help of the perlre documentation maybe you can come up with a
character class that suits your need better.
> 1)delete from the first word on?.
s/\b.*//;
# or
s/\w+.*//;
# or
s/(?<=\W)\w+.*//;
# or
s/^(\W+).*/$1/;
Read perlre to understand what they are doing, and pick the most
appropriate one. Some of the above are a bit dumb (esp. the third), but
they may be helpful when you decide to change the character classes
around.
> 2)delete after the first word on?.
s/\b\W.*//;
# or
s/(?<=\w)\W.*//;
# or
s/(\w+).*/$1/;
# or
s/^(\W+\w+).*/$1/;
# or
s/\b(\w+?)\b.*/$1/;
> 3)delete after the second word on?.
s/(\w+\W+\w+).*/$1/;
There are probably others, but I'm getting a bit tired. you should be
able to figure it out now, with the perlre documentation and these
examples.
None of the above work if the match doesn't succeed. But it's hard to
know whether they should.
Martien
--
Martien Verbruggen |
Interactive Media Division | That's not a lie, it's a
Commercial Dynamics Pty. Ltd. | terminological inexactitude.
NSW, Australia |
------------------------------
Date: 24 Feb 2001 20:12:54 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: How can I detect if program is run by cron?
Message-Id: <979pn6$ff1$1@boomer.cs.utexas.edu>
In article <983062291.552983@elaine.furryape.com>,
Alan Barclay <gorilla@elaine.furryape.com> wrote:
>at & batch behave differently from jobs started from crontab's.
>
>As you say, in your test case, the enviroment is read in and
>used to initialize the job's enviroment.
>
>However, jobs run from crontab do not have this step, and therefore
>won't have any variables setup.
Doh! Well, that's confusing, and also irritating, because it means I'm
wrong. Oh well. That's what I get for being too lazy to edit my
crontab and wait the ~30 seconds for whatever entry to run.
- Logan
--
my your his her our their *its*
I'm you're he's she's we're they're *it's*
------------------------------
Date: Sun, 25 Feb 2001 14:31:33 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: How can I detect if program is run by cron?
Message-Id: <slrn99gv4l.pen.mgjv@martien.heliotrope.home>
On 22 Feb 2001 17:54:39 GMT,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>
> use constant INIT_PID => 1; # 0 on some systems (i think)
Just as an aside... The only Unices (which is where init matters) that
have a pid of 0 used it for the swapper, a kernel level process. I've
never seen init at pid 0, but then, I haven't seen all unices.
Martien
--
Martien Verbruggen | Since light travels faster than
Interactive Media Division | sound, isn't that why some people
Commercial Dynamics Pty. Ltd. | appear bright until you hear them
NSW, Australia | speak?
------------------------------
Date: 24 Feb 2001 09:53:35 +0000
From: nobull@mail.com
Subject: Re: Is an array of hashes the best way to do this?
Message-Id: <u9y9uwpfts.fsf@wcl-l.bham.ac.uk>
Ed Waldspurger <ewald@certifichecks.com> writes:
> SC_ItemSKU_0 roadhouseg_526_10
> SC_ItemQTY_0 1
> SC_ItemSKU_1 thirstydog_583_10
> SC_ItemQTY_1 1
> my @cartitems;
> while (<CART>) {
> chomp;
> my ($item, $value) = split /\t/;
> if ($item =~ /SC_Item(\w*)_(\d*)/) {
> $cartitems[$2]{$1} = $value;
> }
> }
> return @cartitems;
Consider returning a reference here for the sake of efficiency.
> I needed a way to read the contents of the file, and then test for
> certain conditions. For example, I want to limit the quantity purchased
> of some products. To do that I am testing like this.
>
> my @cartitems = readcart($cartid);
>
> for (0..(@cartitems-1)) {
Unless you actually need the index for something it would be more
efficient to iterate over the elements of @cartitems itself.
BTW: If you really do need the index then (@cartitems-1) is better
written as $#cartitems
> if (exists $cartitems[$_]{'SKU'}) {
> if ($cartitems[$_]{'SKU'} eq "some_product" &&
> $cartitems[$_]{'QTY'} > 1) {
> # Do something here
> }
> }
> }
>
> This seems very cumbersome. Is there a better data structure I could be
> using, or a more efficient way of testing this condition? The key I am
> testing on may not always exist in the data, so I have to check for it's
> existence or I get "Use of uninitialized value" warnings.
If you are not bothered about knowing if the the datum in question is
0 you can simply use || '' to supress the warning. You can also (for
$] >= 5.00) use 'no warnings qw( uninitialized )'. It is good
practice to always suppress warnings/stricures for as small a scope as
possible. You can even use do{} to supress them just within an
expression.
Also note that && is a "lazy" oprtator so there's no need to use
nested ifs in your example above.
my $cartitems = readcart($cartid); # Returns ARRAY-ref
for my $item (@$cartitems) {
if ( do {
no warnings qw( uninitialized );
$item->{SKU} eq "some_product" && $item->{QTY} > 1;
} ) {
# Do something here
}
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sun, 25 Feb 2001 04:30:52 GMT
From: "Michael Weaver" <mike@mannacabana.com>
Subject: regexp question
Message-Id: <0U%l6.169210$Tl3.32848847@typhoon.tampabay.rr.com>
I'm trying to write a regular expression to parse and HTML SELECT element
and extract the values of each option.
An example string would be:
<option id='testing' value='0' class='something'>no</option>
And I want to extract the "value='0'"
However, keep in mind that there may or may not be anything between "option"
and "value" and they actually may not even be a "value" string.
Here's what I have so far:
/<\s*option(.*)(?:value\s*=\s*['|"].*['|"])?(.*)>.*<\/option>/gi
Everything (including the "value" clause) goes into pattern memory 1. But
when I make the first (.*) non-greedy by using (.*?), everything goes into
pattern memory 2. I can't seem to get the regexp to pick up the optional
"value" clause.
Any help would be greatly appreciated!
Thanks,
Mike
------------------------------
Date: 24 Feb 2001 09:55:50 +0000
From: nobull@mail.com
Subject: Re: server question
Message-Id: <u9vgq0pfq1.fsf@wcl-l.bham.ac.uk>
"Terry" <terry_s@northstate.net> writes:
> Subject: server question
[snip]
> with Omni httpd professional web server.
You are right - you have a question about the configuration of Omni,
not related to Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sun, 25 Feb 2001 02:12:17 GMT
From: Jeffrey Porter <jandkporter@mediaone.net>
Subject: Simple(?) server process
Message-Id: <3A986A7A.AABF451A@mediaone.net>
I have to implement a process that wakes up every couple of seconds,
tests a request queue and if there is activity, run a seperate process.
Simple right? Well there are a couple of caveats... 1) There can be
some long running processes here so i can't wait for the process to end
before I check the incomming requests again. 2). There can be no more
that x number of processes running, 2). If a process dies, it must be
removed from a "processes running queue" so I can service another...
All of this is on a single machine so hopefully that makes it easier. I
don't need output from the processes I'm spawning, nor do I or need to
feed the process from the server so I was thinking of setting up a queue
kicking off background processes but don't know how to effectively deal
with the background PID's and their returns or failures.
The logistics of the queue are pretty simple... any ideas on how to
accomplish this would be greatly appreciated
------------------------------
Date: 24 Feb 2001 20:23:55 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Simple(?) server process
Message-Id: <979qbr$fnb$1@boomer.cs.utexas.edu>
In article <3A986A7A.AABF451A@mediaone.net>,
Jeffrey Porter <jandkporter@mediaone.net> wrote:
>I have to implement a process that wakes up every couple of seconds,
>tests a request queue and if there is activity, run a seperate process.
>Simple right? Well there are a couple of caveats... 1) There can be
>some long running processes here so i can't wait for the process to end
>before I check the incomming requests again. 2). There can be no more
>that x number of processes running, 2). If a process dies, it must be
>removed from a "processes running queue" so I can service another...
In other words, you need to do exactly the same thing as cron, except
that you have to test whether a queue is empty or not instead of
testing whether the time matches the current one or not.
There are two approaches that I can think of.
The first is the one that cron uses. What you do is you run the wait()
call to block until a child process exits, but just before you call
wait, you use alarm() to arrange for a SIGALRM to arrive and interrupt
the wait() call after N seconds.
That approach obviously works, since cron (the one on Solaris) uses it,
and it doesn't crash and stuff, but personally I think using signals is
a recipe for a buggy program, so avoid them.
So, instead, what I'd do is run a loop that looks like this:
while (1)
{
sleep ($sleep_interval);
# make a note of how many children have exited
# since last time
while (-1 != $pid = waitpid(-1,&WNOHANG))
{
$num_children--;
}
# start a new child if necessary
if (queue_non_empty() and $num_children < $max_children)
{
fork_a_child() && $num_children++;
}
}
It's true that you'll have some zombie processes waiting around for up
to $sleep_interval seconds, but this is probably not a big problem as
long as $sleep_interval isn't too big.
Hope that helps.
Note that I've removed comp.lang.perl from the Newsgroups: line
because comp.lang.perl doesn't exist and hasn't for years and years.
- Logan
--
my your his her our their *its*
I'm you're he's she's we're they're *it's*
------------------------------
Date: Sun, 25 Feb 2001 02:46:31 GMT
From: Jeffrey Porter <jandkporter@mediaone.net>
Subject: Re: Simple(?) server process
Message-Id: <3A98727F.CA25C41E@mediaone.net>
thanks for responding Logan. I'm not entirely sure of all your
explainations but I'll run with it all the same. I'll explain a little more
detail to see if this changes the equations any...
I'm going to be parsing a DB table for user requests that need to be run.
These requests are constructed and subsequently processed and (hopefully)
end successfully.
I'm not versed in CRON (OK showing the newbie status) but I'll take you're
word for it.
------------------------------
Date: 24 Feb 2001 22:38:14 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Simple(?) server process
Message-Id: <97a27m$gmf$1@boomer.cs.utexas.edu>
In article <3A98727F.CA25C41E@mediaone.net>,
Jeffrey Porter <jandkporter@mediaone.net> wrote:
>I'm going to be parsing a DB table for user requests that need to be run.
>These requests are constructed and subsequently processed and (hopefully)
>end successfully.
That sounds like something that should work just fine with the the
waitpid/fork if work/sleep loop I described.
>I'm not versed in CRON (OK showing the newbie status) but I'll take you're
>word for it.
cron was a little bit of a red herring, but your problem is very much
like what it has to do. It wakes up every 60 seconds and checks if the
time matches any of its users' jobs, and if so, starts the job. It
also notices when jobs have finished and e-mails the results to the
user who scheduled them.
- Logan
--
my your his her our their *its*
I'm you're he's she's we're they're *it's*
------------------------------
Date: Sun, 25 Feb 2001 02:41:21 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: SMTP server
Message-Id: <slrn99gs65.bts.efflandt@efflandt.xnet.com>
On 24 Feb 2001, The Mosquito ScriptKiddiot <anotherway83@aol.com> wrote:
>
>sorry if this mite sound off-topic, but i haven't been able to find a decent
>SMTP server...i've looked all over, meaning i've searched using search engines,
>and it's true that MANY so-called "valid" hits r returned...sites that
>literally contain lists of what they call "free" smtp servers, but when u try
>them, they're all fake...the ones that work say stuff like "relaying
>denied"....
Usually you can only use an SMTP server on or related to the network you
are connected to, ie: when connected to your ISP, you can use your ISP's
SMTP. For CGI, you would use the SMTP server of your web host (if
allowed).
The Perl alternative would be to use a combination of DNS and Mail modules
to look up the MX record and send it directly to the recipient's mail
server.
Or do like I do and roll your own (install Linux or FreeBSD on your PC).
Although, that works best if you have a static IP, or at least hostname.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Sun, 25 Feb 2001 15:10:11 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: splice question
Message-Id: <slrn99h1d3.pen.mgjv@martien.heliotrope.home>
[Please, in the future, put your reply _after_ the suitably trimmed text
you reply to. It's the generally accepted quoting style on this group,
and Usenet in general]
On Sun, 25 Feb 2001 01:03:01 GMT,
Joseph Pepin <jdpepin@optonline.net> wrote:
> "Charles K. Clarkson" <c_clarkson@hotmail.com> wrote in message
> news:36FEC83E831D28D2.6881EE70E5A1EB7F.6BA0D72862B17289@lp.airnews.net...
>>
>> "Joseph Pepin" <jdpepin@optonline.net> wrote in message
>> news:x5Wl6.7692$Vj5.1529479@news02.optonline.net...
>> : "Rick Delaney" <rick.delaney@home.com> wrote in message
>> : news:3A982C86.F855A0E8@home.com...
>> : > [posted & mailed]
>> : >
>> : > Joseph Pepin wrote:
>> : > >
>> : > > @a = (1, 2, 3, 4, 5, 6);
>> : > >
>> : > > @b = splice @a, 0, 4, $a[2], $a[3];
>> : > >
>> : > > However, what I get in @b is (1, 2, undef, undef). @a is left with
>> (3,
>> : 4,
>> : > > 5, 6), what I wanted. Shouldn't @b be (1, 2, 3, 4) ?
>> : >
>> : > Yup, and it is in 5.005_03 and up. What version are you using?
>> :
>> : 5.6.0. The same thing happens on both Solaris (built from scratch) and
>> : ActiveState 623.
>> :
>>
>> I ran:
>> my @a = (1, 2, 3, 4, 5, 6);
>> my @b = splice @a, 0, 4, $a[2], $a[3];
>> print Dumper(\@a, \@b);
>>
>> and got:
>> $VAR1 = [
>> 3,
>> 4,
>> 5,
>> 6
>> ];
>> $VAR2 = [
>> 1,
>> 2,
>> 3,
>> 4
>> ];
>>
>> with ActivePerl 5.6.0.623 on Win98.
>
> Interesting. If I remove the double quotes around the "$_" in the below sub
> show, I get the same answer. Now maybe I have another question.
You still haven't told us the version and OS of the Perl you're running.
> sub show { my $label = shift; print $label, ': ', join(', ', map(defined
> $_ ? "$_" : 'undef', @_)), "\n";}
>
> my @a = (1, 2, 3, 4, 5, 6, 7, 8);
> my @b = @a;
>
> show('before', @a);
> show('line a', splice(@a, 0, 4, $a[2], $a[3]));
> show('line b', splice(@b, 0, 4, $b[2] + 0, $b[3] + 0));
> show('after', @a);
>
> before: 1, 2, 3, 4, 5, 6, 7, 8
> line a: 1, 2, undef, undef
> line b: 1, 2, 3, 4
> after: 3, 4, 5, 6, 7, 8
I can reproduce this on Linux, Perl 5.6.0, perl 5.004_05 and 5.005_03.
What is even more interesting:
$ perl -wl
sub show { print join ":", map {$_ || "undef"} @_ }
my @a = (1, 2, 3, 4, 5, 6, 7, 8);
show splice @a, 0, 4, $a[2], $a[3];
__END__
1:2:3:4
$ perl -wl
sub show { print join ":", map {$_ || "undef"} @_ }
my @a = (1, 2, 3, 4, 5, 6, 7, 8);
print "@a";
show splice @a, 0, 4, $a[2], $a[3];
__END__
1 2 3 4 5 6 7 8
1:2:undef:undef
Now.. try to explain that... If I ave a look at the array before doing
the splice, the elements turn out to be undef. If I don't, they're what
$a[2] and $a[3] were before the splice.
The problem seems to be related to stringification of the elements of
@a, _before_ the splice:
$ perl -wl
sub show { print join ":", map {$_ || "undef"} @_ }
my @a = (1, 2, 3, 4, 5, 6, 7, 8);
"$_" for @a;
Useless use of string in void context at - line 3.
show splice @a, 0, 4, $a[2], $a[3];
__END__
1:2:undef:undef
$ perl -wl
sub show { print join ":", map {$_ || "undef"} @_ }
my @a = (1, 2, 3, 4, 5, 6, 7, 8);
$_ for @a;
Useless use of a variable in void context at - line 3.
show splice @a, 0, 4, $a[2], $a[3];
__END__
1:2:3:4
Looks like it might be worth a bug report. I am not saying that I would
expect Perl to behave either way, although it should probably behave as
you expect. But there being a difference in the way these two work is
not acceptable.
If you don't know how to submit a bug report, let me know, and I'll
prepare one.
Martien
--
Martien Verbruggen |
Interactive Media Division | Hi, Dave here, what's the root
Commercial Dynamics Pty. Ltd. | password?
NSW, Australia |
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 352
**************************************