[28470] in Perl-Users-Digest
Perl-Users Digest, Issue: 9834 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 11 21:05:54 2006
Date: Wed, 11 Oct 2006 18:05:06 -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 Wed, 11 Oct 2006 Volume: 10 Number: 9834
Today's topics:
Changes in handling of backticks + arrays between 5.8.0 <robb@acm.org>
Re: Changes in handling of backticks + arrays between 5 xhoster@gmail.com
Re: Changes in handling of backticks + arrays between 5 (Chris Mattern)
Re: Changes in handling of backticks + arrays between 5 <sherm@Sherm-Pendleys-Computer.local>
Re: Changes in handling of backticks + arrays between 5 <robb@acm.org>
Re: Filtering duplicates out of an array anno4000@radom.zrz.tu-berlin.de
Re: Firefox Won't Execute My Perl Script <mgarrish@gmail.com>
Re: Firefox Won't Execute My Perl Script <wahab@chemie.uni-halle.de>
Input into Net::Netmask mdeggers@gmail.com
Re: Input into Net::Netmask <tadmc@augustmail.com>
Re: Input into Net::Netmask (reading news)
Re: IO::Prompt with Keymap anno4000@radom.zrz.tu-berlin.de
Re: LWP and Unicode <tzz@lifelogs.com>
Re: LWP and Unicode <hjp-usenet2@hjp.at>
Re: Parsing HTML - using HTML::TreeBuilder <bartthebear@gmail.com>
Re: replace variable with same variable <bart@nijlen.com>
Re: replace variable with same variable anno4000@radom.zrz.tu-berlin.de
Re: replace variable with same variable <uri@stemsystems.com>
Standard output problem wesphillips@gmail.com
Standard output problem wesphillips@gmail.com
Re: Standard output problem <bik.mido@tiscalinet.it>
Re: Standard output problem <jgibson@mail.arc.nasa.gov>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Oct 2006 12:32:03 -0700
From: "robb@acm.org" <robb@acm.org>
Subject: Changes in handling of backticks + arrays between 5.8.0 and 5.8.4?
Message-Id: <1160595123.026368.252460@h48g2000cwc.googlegroups.com>
Hi,
I'm testing code on a new server, and found a piece of code that works
on the old, but not the new:
@cal = `/usr/bin/cal 5 2006`
On the 5.8.0 system, it returns a list of the lines of output. On the
new system, the list is empty.
I'm personally not too familiar with this construction. Is it
supported?
Thanks,
Robb
------------------------------
Date: 11 Oct 2006 19:37:47 GMT
From: xhoster@gmail.com
Subject: Re: Changes in handling of backticks + arrays between 5.8.0 and 5.8.4?
Message-Id: <20061011154052.263$uD@newsreader.com>
"robb@acm.org" <robb@acm.org> wrote:
> Hi,
>
> I'm testing code on a new server, and found a piece of code that works
> on the old, but not the new:
>
> @cal = `/usr/bin/cal 5 2006`
>
> On the 5.8.0 system, it returns a list of the lines of output. On the
> new system, the list is empty.
Does /usr/bin/cal exist on the new server? Did you check "$?" and "$!" for
errors?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 11 Oct 2006 20:12:11 -0000
From: syscjm@sumire.eng.sun.com (Chris Mattern)
Subject: Re: Changes in handling of backticks + arrays between 5.8.0 and 5.8.4?
Message-Id: <12iqk0rfgpb1h12@corp.supernews.com>
In article <1160595123.026368.252460@h48g2000cwc.googlegroups.com>,
robb@acm.org wrote:
>Hi,
>
>I'm testing code on a new server, and found a piece of code that works
>on the old, but not the new:
>
>@cal = `/usr/bin/cal 5 2006`
>
>On the 5.8.0 system, it returns a list of the lines of output. On the
>new system, the list is empty.
>
>I'm personally not too familiar with this construction. Is it
>supported?
>
>Thanks,
>Robb
>
Obvious question first: On the new system, does /usr/bin/cal *exist*?
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Wed, 11 Oct 2006 15:43:48 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Changes in handling of backticks + arrays between 5.8.0 and 5.8.4?
Message-Id: <m2fyduvdsb.fsf@Sherm-Pendleys-Computer.local>
"robb@acm.org" <robb@acm.org> writes:
> I'm testing code on a new server, and found a piece of code that works
> on the old, but not the new:
>
> @cal = `/usr/bin/cal 5 2006`
>
> On the 5.8.0 system, it returns a list of the lines of output. On the
> new system, the list is empty.
>
> I'm personally not too familiar with this construction. Is it
> supported?
Given only a minor patchlevel version difference, such a major change in
Perl would be the *last* thing I'd suspect.
Check the value of $? to see if there was a problem running cal.
Details about $? can be found in 'perldoc perlvar'.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 11 Oct 2006 17:29:06 -0700
From: "robb@acm.org" <robb@acm.org>
Subject: Re: Changes in handling of backticks + arrays between 5.8.0 and 5.8.4?
Message-Id: <1160612946.572542.5570@h48g2000cwc.googlegroups.com>
Thanks for all the replies.
> Given only a minor patchlevel version difference, such a major change in
> Perl would be the *last* thing I'd suspect.
>
> Check the value of $? to see if there was a problem running cal.
>
> Details about $? can be found in 'perldoc perlvar'.
Thanks for the pointers to the proper error variables.
This is part of a piece code set that I've inherited and does no error
checking.
And now it's being run on a new server in a chroot environment, but
we're not allowed to log in interactively as the chrooted user...
So it took a little while to realize that /usr/bin/cal was there, but
not where the cgi process was looking for it.
------------------------------
Date: 11 Oct 2006 20:15:13 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Filtering duplicates out of an array
Message-Id: <4p51mhFh1efoU1@news.dfncis.de>
Bigus <bigus@abdcdefghijk.com> wrote in comp.lang.perl.misc:
> "John W. Krahn" <someone@example.com> wrote in message
> news:UJ3Xg.17077$H7.11961@edtnps82...
>
> >> There's a nice compact one-liner for making non-multidimensional arrays
> >> uniqye, ie:
> >>
> >> @array = do {my %h; grep {!$h {$_} ++} @array;
> >>
> >> Can that be modified to do what I want?
> >
> > @array = do {my %h; grep {!$h {$_->[0]} ++} @array;
>
> actually, there is a related question - how do you make it case insensitive?
>
> This doesn't work:
>
> @array = do {my %h; grep {!$h {lc($_->[0])} ++} @array;
Doesn't work how? It selects members (which must be array refs) from
the array so that their first elements are unique. It ignores case in
the comparison, but doesn't change it.
Anno
------------------------------
Date: 11 Oct 2006 14:08:35 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: Firefox Won't Execute My Perl Script
Message-Id: <1160600915.453677.50870@h48g2000cwc.googlegroups.com>
Mirco Wahab wrote:
> Thus spoke Sherm Pendley (on 2006-10-11 16:36):
> > "Matt Garrish" <mgarrish@gmail.com> writes:
> >> Sherm Pendley wrote:
> >>> robic0 writes:
> >>> > Hey Jew there must be something that is Perl used heavily in page p=
roduction.
> >>> > Jeez what could it be. Oh well, it must be a fuckin secret........
> >>> 'PerlScript' ne 'Perl'. Perl is used heavily. PerlScript - ActiveStat=
e's
> >>> Windows Scripting Host support for Perl - is very rarely used.
> >> True and not so true. ...
> >
> > 'very rarely' ne 'never'. :-)
> > ...
> > Robic0 took J=FCrgen's statement as saying that *Perl itself* is rarely=
used.
> > I guess he just can't resist an opportunity to make a fool of himself in
> > public.
>
There's a surprise! I'd 'a' never thunked that in million years... ; )
> Maybe there's still some truth in it
> (aehm, I mean - "with the Perl usage"),
> in a sense that Perl lives by a bunch
> of clever guys and it will die with them,
> -- like the swords in warfare died with
> the men who lived by them ...
>
Sorry, are you trying to be prophetic? I haven't followed the group a
lot lately, but you seem to have a thing for sword metaphors. If you
want to prophesy the demise of Perl get in line with everyone who's
been predicting its doom since the advent of the web.
Matt
------------------------------
Date: Thu, 12 Oct 2006 01:54:21 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Firefox Won't Execute My Perl Script
Message-Id: <egk0ge$hc0$1@mlucom4.urz.uni-halle.de>
Thus spoke Matt Garrish (on 2006-10-11 23:08):
> Mirco Wahab wrote:
>> Thus spoke Sherm Pendley (on 2006-10-11 16:36):
>> > "Matt Garrish" <mgarrish@gmail.com> writes:
>> >> Sherm Pendley wrote:
>> >>> robic0 writes:
>> >>> > Hey Jew there must be something that is Perl used heavily in page production.
>> >>> > Jeez what could it be. Oh well, it must be a fuckin secret........
>> >>> 'PerlScript' ne 'Perl'. Perl is used heavily. PerlScript - ActiveState's
>> >> True and not so true. ...
>> > 'very rarely' ne 'never'. :-)
>> > ...
>> > Robic0 took Jürgen's statement as saying that *Perl itself* is rarely used.
>> > I guess he just can't resist an opportunity to make a fool of himself in
>> > public.
>
>> [trust no one but this ... (from the "riddle of the steel")]
>> ... like the swords in warfare died with the men who lived by them ...
>
> Sorry, are you trying to be prophetic? I haven't followed the group a
> lot lately, but you seem to have a thing for sword metaphors.
IIRC did I do *one* another thing like that
where I tried to be funny or so ...
> If you want to prophesy the demise of Perl get in line with
> everyone who's been predicting its doom since the advent of
> the web.
Actually, the "advent of the web" was (afaik) in
coincidence with the advent of Perl5 and it's CGI
revolution of things.
BTW, I always tell younger people to use Perl and
give them examples¹ for this and for that. When they
leave and go into some other context, they will never
do any Perl out there, they'd do Ruby or Python or
the like - if they don't get into Java in the first
place.
Why is that? Am I wrong and short sighted? Don't
I see the whole thing? As much as I like to work
with Perl, as dark I foresee its perspectives.
Perl was Perl, because Larry made something extra-
ordinary in a (the?) Phase of his life when he
was able to. It was something like he got his
"divine right".
OK, we went far away from the topic, so I'll stop here ;-)
Regards
M.
¹ thats hopefully not the reason why ... ;-)
------------------------------
Date: 11 Oct 2006 16:08:02 -0700
From: mdeggers@gmail.com
Subject: Input into Net::Netmask
Message-Id: <1160608082.792388.226670@e3g2000cwe.googlegroups.com>
I am trying to use Net::Netmask and running into a bit of a challenge.
This code snippet works as expected:
use Net::Netmask;
my $block = new Net::Netmask('10.10.20.0/24');
$hashBlock{"vlan_20"} = $block;
I can then recover information concerning vlan_20.
However, if I try to do this with an array of network blocks like the
following, I get an error with new.
@blocks = ('10.10.10.0/24','10.10.20.0/24');
@vlans = ('vlan_10','vlan_20');
for ($i = 0; $i < 3; $i++ )
{
my $block = new Net::Netmask($blocks[$i]);
$hashBlock{$vlans[$i]} = $block;
}
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in string eq at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in string eq at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in pattern match (m//) at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
Use of uninitialized value in concatenation (.) or string at
/usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 113.
This is running perl 5.8.7 under cygwin on Windows / XP Professional
and a fresh copy of Net::Netmask from CPAN.
I've tried "'10.10.10.0/24'" as well in the array.
Thoughts - other than loading everything manually . . . . . .
/mde/
------------------------------
Date: Wed, 11 Oct 2006 18:17:44 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Input into Net::Netmask
Message-Id: <slrneiquso.umg.tadmc@magna.augustmail.com>
mdeggers@gmail.com <mdeggers@gmail.com> wrote:
> @blocks = ('10.10.10.0/24','10.10.20.0/24');
What is the highest valid index for the @blocks array?
> for ($i = 0; $i < 3; $i++ )
What index values will $i take in this loop?
> Thoughts -
Don't use the 3-part for loop, it is easy to introduce an
Off By One Error, as you have seen:
foreach my $i ( 0 .. $#blocks )
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 12 Oct 2006 01:03:16 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: Input into Net::Netmask
Message-Id: <ovgXg.5971$Lv3.410@newsread1.news.pas.earthlink.net>
On 10/11/2006 06:08 PM, mdeggers@gmail.com wrote:
> I am trying to use Net::Netmask and running into a bit of a challenge.
>
> This code snippet works as expected:
>
> use Net::Netmask;
>
> my $block = new Net::Netmask('10.10.20.0/24');
> $hashBlock{"vlan_20"} = $block;
>
> I can then recover information concerning vlan_20.
>
> However, if I try to do this with an array of network blocks like the
> following, I get an error with new.
>
> @blocks = ('10.10.10.0/24','10.10.20.0/24');
> @vlans = ('vlan_10','vlan_20');
>
> for ($i = 0; $i < 3; $i++ )
Your "@blocks" array contains two elements, but you process four.
> {
> my $block = new Net::Netmask($blocks[$i]);
For the third and fourth elements, $blocks[$i] is undefined.
> $hashBlock{$vlans[$i]} = $block;
> }
>
> Use of uninitialized value in pattern match (m//) at
> /usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47.
> Use of uninitialized value in pattern match (m//) at
> /usr/lib/perl5/site_perl/5.8/Net/Netmask.pm line 47. [...]
HTH
--
Mumia W.
paduille.4059.mumia.w@earthlink.net
This is a temporary e-mail to help me catch some s-p*á/m.
------------------------------
Date: 11 Oct 2006 19:20:32 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: IO::Prompt with Keymap
Message-Id: <4p4ug0Fh6fhqU1@news.dfncis.de>
Dale <dale.gerdemann@googlemail.com> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de wrote:
>
> > Use a hash instead of nested ?:
>
> A hash is, I suppose, better. But my real concern was that I had to
> hack a new version of IO::Prompt. Would there be any way to use
> IO::Prompt (or a similar module) as is, and still apply a special
> keymap?
Then why did you ask a different question? Your original post doesn't
even mention IO::Prompt.
Apply a special key map to what? It should be trivial to make it
print a Cyrillic prompt, but if you expect the user to type Latin
and see Cyrillic, I doubt if there is such a provision.
You could try to make IO::Prompt use a modified version of
Term::Readkey and do the translation there.
Anno
------------------------------
Date: Wed, 11 Oct 2006 19:08:10 +0100
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: LWP and Unicode
Message-Id: <g694puaraid.fsf@lifelogs.com>
On 10 Oct 2006, hjp-usenet2@hjp.at wrote:
On 2006-10-10 18:15, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Ted Zlatanov wrote:
>>> 2) why not do a vote to change the charter to make UTF-8 the charset
>>> for c.l.p.m?
>>
>> Well, that's like a small town deciding that within its boundaries everyone
>> should drive on the left side of the road.
>
> Seriously: As much as I liked the USEFOR proposal to make UTF-8 the
> default charset (instead of ASCII) on usenet, and as much as I dislike
> MIME, I don't think declaring UTF-8 to be the default charset for a
> single group would be a good idea. Charsets should be properly declared
> in a MIME Content-Type header. As long as the charset is correctly
> encoded, I think any reasonably widespread charset (and that includes
> UTF-8) should be acceptable.
Thanks, Peter. I agree with all you said, except I think UTF-8 is not
a charset, contrary to what MIME claims, right? UCS is the charset,
UTF-8 is an encoding. Is UCS the real charset when Content-Type
specifies "charset=utf-8"?
This layers bizarrely on top of the MIME Content-Transfer-Encoding, of
course. Will UCS data be encoded twice in the end?
Ted
------------------------------
Date: Wed, 11 Oct 2006 23:04:40 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: LWP and Unicode
Message-Id: <slrneiqn38.f4m.hjp-usenet2@yoyo.hjp.at>
On 2006-10-11 18:08, Ted Zlatanov <tzz@lifelogs.com> wrote:
> On 10 Oct 2006, hjp-usenet2@hjp.at wrote:
>> On 2006-10-10 18:15, Jürgen Exner <jurgenex@hotmail.com> wrote:
>>> Ted Zlatanov wrote:
>>>> 2) why not do a vote to change the charter to make UTF-8 the charset
>>>> for c.l.p.m?
[...]
>> Seriously: As much as I liked the USEFOR proposal to make UTF-8 the
>> default charset (instead of ASCII) on usenet, and as much as I dislike
>> MIME, I don't think declaring UTF-8 to be the default charset for a
>> single group would be a good idea. Charsets should be properly declared
>> in a MIME Content-Type header. As long as the charset is correctly
>> encoded, I think any reasonably widespread charset (and that includes
>> UTF-8) should be acceptable.
>
> Thanks, Peter. I agree with all you said, except I think UTF-8 is not
> a charset, contrary to what MIME claims, right?
Right. The terminology is a mess. What MIME calls a "charset" is more
commonly known as a "character encoding". (In fact I thought that one of
the MIME RFCs mentions that, I can't find it right now)
When I try to explain that stuff I distinguish between
* character set - a set of characters in the mathematical sense, i.e.
unordered.
* coded character set - as above, but each character is associated with
a numerical code.
* character encoding - a particular mapping of a coded character set
onto sequences of octets (or bits). MIME calls this a "charset", the
Unicode standard calls it a "transformation format".
I use the term "charset" only when I talk about MIME, otherwise I talk
of "(coded) character sets" and don't abbreviate them to "charset".
> UCS is the charset, UTF-8 is an encoding. Is UCS the real charset
> when Content-Type specifies "charset=utf-8"?
Yes.
> This layers bizarrely on top of the MIME Content-Transfer-Encoding, of
> course. Will UCS data be encoded twice in the end?
This can happen, yes. If a message with UTF-8 content is to be
transmitted over a channel which isn't 8bit clean, a
Content-Transfer-Encoding of quoted-printable or base64 must be applied.
Think of UTF-8 as a mapping from a sequence of 16-bit (or 32-bit)
quantities onto a sequence of 8-bit quantities, and quoted-printable or
base64 as a mapping from a sequence of 8-bit quantities onto a sequence
of 7-bit quantities. (The remaining Content-Transfer-Encodings 7bit,
8bit and binary are transparent)
(Of course it doesn't stop there: SMTP and NNTP do a trivial bit of
extra encoding ("dot-stuffing"), TCP and IP only paste their headers
before chunks of data, but PPP for example is a bit more complicated,
and I don't really want to know what a DSL modem does to my precious
bits :-)).
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 11 Oct 2006 11:36:40 -0700
From: "Bart the bear" <bartthebear@gmail.com>
Subject: Re: Parsing HTML - using HTML::TreeBuilder
Message-Id: <1160591800.827766.298420@i3g2000cwc.googlegroups.com>
John Bokma wrote:
> $tree->delete;
Save the trees!
------------------------------
Date: 11 Oct 2006 12:07:24 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: replace variable with same variable
Message-Id: <1160593644.108929.141400@h48g2000cwc.googlegroups.com>
Paul Lalli wrote:
> Bart Van der Donck wrote:
> > $line=~s/PILOT_INC=[2-8],/$& NGHBR_SRCH_MODE = 0,/g;
>
> Please don't do that. Using the $&, $', and $` variables slow down ALL
> regular expressions in the entire program even if you only use any of
> them once.
>
> $line =~ /(PILOT_INC=[2-8])/$1 NGHBR_SRCH_MODE = 0,/g;
My tests seem to indicate the opposite:
---------------------------------------------------------------
#!/perl
use strict;
use warnings;
use Time::HiRes qw (time);
my $start = Time::HiRes::time();
for (1..100000) {
my $line="PILOT_INC=6,";
$line =~s/(PILOT_INC=[2-8])/$1 NGHBR_SRCH_MODE = 0,/g;
}
print 'Runtime Paul (sec.): ' . (Time::HiRes::time() - $start);
Says (x12):
Runtime Paul: 0.640222072601318
Runtime Paul: 0.608975887298584
Runtime Paul: 0.608963012695313
Runtime Paul: 0.624594926834106
Runtime Paul: 0.608951091766357
Runtime Paul: 0.624592065811157
Runtime Paul: 0.624598026275635
Runtime Paul: 0.608963012695313
Runtime Paul: 0.62458610534668
Runtime Paul: 0.60896110534668
Runtime Paul: 0.60896897315979
Runtime Paul: 0.608973026275635
---------------------------------------------------------------
#!/perl
use strict;
use warnings;
use Time::HiRes qw (time);
my $start = Time::HiRes::time();
for (1..100000) {
my $line="PILOT_INC=6,";
$line =~ s/PILOT_INC=[2-8],/$& NGHBR_SRCH_MODE = 0,/g;
}
print 'Runtime Bart (sec.): ' . (Time::HiRes::time() - $start);
Says (x12):
Runtime Bart: 0.577714920043945
Runtime Bart: 0.562077045440674
Runtime Bart: 0.577706098556519
Runtime Bart: 0.577709913253784
Runtime Bart: 0.577713012695313
Runtime Bart: 0.577725887298584
Runtime Bart: 0.562100887298584
Runtime Bart: 0.57771897315979
Runtime Bart: 0.562102079391479
Runtime Bart: 0.577723026275635
Runtime Bart: 0.577722072601318
Runtime Bart: 0.577724933624268
---------------------------------------------------------------
I'm not sure how to interpret these results then (Perl 5.8.4. WinXP).
--
Bart
------------------------------
Date: 11 Oct 2006 19:51:07 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: replace variable with same variable
Message-Id: <4p509bFhaupaU1@news.dfncis.de>
Bart Van der Donck <bart@nijlen.com> wrote in comp.lang.perl.misc:
> Paul Lalli wrote:
>
> > Bart Van der Donck wrote:
> > > $line=~s/PILOT_INC=[2-8],/$& NGHBR_SRCH_MODE = 0,/g;
> >
> > Please don't do that. Using the $&, $', and $` variables slow down ALL
> > regular expressions in the entire program even if you only use any of
> > them once.
> >
> > $line =~ /(PILOT_INC=[2-8])/$1 NGHBR_SRCH_MODE = 0,/g;
>
> My tests seem to indicate the opposite:
The effect isn't always clear. It is most pronounced with many
small matches on a long string, as in the following example:
use Benchmark;
my $str = ('a' x 100 . 'x') x 500;
my $x = $&;
timethis -2, sub { 1 while $str =~ /x/g }
On my machine this results in
3 wallclock secs ( 0.57 usr + 1.58 sys = 2.15 CPU) @ 10.70/s (n=23)
After commenting out the line with $&, it is more than 100 times faster:
2 wallclock secs ( 2.04 usr + 0.03 sys = 2.07 CPU) @ 1373.91/s (n=2844)
Since it is hard to tell in advance whether a program will ever get
in such a situation it is practice to avoid the match variables
altogether.
Anno
------------------------------
Date: Wed, 11 Oct 2006 16:23:59 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: replace variable with same variable
Message-Id: <x77iz6vbxc.fsf@mail.sysarch.com>
>>>>> "BVdD" == Bart Van der Donck <bart@nijlen.com> writes:
BVdD> Paul Lalli wrote:
>> Bart Van der Donck wrote:
>> > $line=~s/PILOT_INC=[2-8],/$& NGHBR_SRCH_MODE = 0,/g;
>>
>> Please don't do that. Using the $&, $', and $` variables slow down ALL
>> regular expressions in the entire program even if you only use any of
>> them once.
>>
>> $line =~ /(PILOT_INC=[2-8])/$1 NGHBR_SRCH_MODE = 0,/g;
BVdD> My tests seem to indicate the opposite:
BVdD> ---------------------------------------------------------------
BVdD> #!/perl
BVdD> use strict;
BVdD> use warnings;
use Benchmark. what you are doing is clunky and hard to compare many results.
BVdD> I'm not sure how to interpret these results then (Perl 5.8.4. WinXP).
well, what you have shown is not relevent to the actual problem with
$&. anno showed a better test which highlights the issue. it is not the
speed of using $& itself but that using $& ANYWHERE in your program
slows down ALL other s/// ops which do grabbing. this is because $& is
global and could be used anywhere at any place in the code so all s///
ops need to do an extra copy of their original string in case some $&
will refer to it. by using $1 you will only copy the original string in
s/// when you actually need it for the $1.
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: 11 Oct 2006 13:35:10 -0700
From: wesphillips@gmail.com
Subject: Standard output problem
Message-Id: <1160598910.311902.207580@h48g2000cwc.googlegroups.com>
I have a perl script, it is very basic:
#!/usr/bin/perl -w
#test.pl
print "test\n";
The test.pl file is executable (permissions are 755). If I run this
script like this:
perl ./test.pl
I get the expected output, but if I run it like this:
./test.pl
I don't get anything at all. I have induced errors into the script to
see if I get the error messages, but I still get nothing. If I run the
script with the errors by explicitly calling perl, I see the error
output like I expect to. I have a second script in the same directory
that DOES work when called directly, so I don't know what could be
wrong. I have also changed the first line so that it looks like this:
#!/usr/bin/perly -w
and I get the expected error from bash stating that it cannot find the
interpreter called "perly"
Any ideas?
------------------------------
Date: 11 Oct 2006 13:35:27 -0700
From: wesphillips@gmail.com
Subject: Standard output problem
Message-Id: <1160598927.191712.294260@m7g2000cwm.googlegroups.com>
I have a perl script, it is very basic:
#!/usr/bin/perl -w
#test.pl
print "test\n";
The test.pl file is executable (permissions are 755). If I run this
script like this:
perl ./test.pl
I get the expected output, but if I run it like this:
./test.pl
I don't get anything at all. I have induced errors into the script to
see if I get the error messages, but I still get nothing. If I run the
script with the errors by explicitly calling perl, I see the error
output like I expect to. I have a second script in the same directory
that DOES work when called directly, so I don't know what could be
wrong. I have also changed the first line so that it looks like this:
#!/usr/bin/perly -w
and I get the expected error from bash stating that it cannot find the
interpreter called "perly"
Any ideas?
------------------------------
Date: 11 Oct 2006 23:39:55 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Standard output problem
Message-Id: <mmoqi2hiultsmsnomfhtpogpvch7d33gsn@4ax.com>
On 11 Oct 2006 13:35:10 -0700, wesphillips@gmail.com wrote:
>Subject: Standard output problem
No!
>I have a perl script, it is very basic:
>
>#!/usr/bin/perl -w
>#test.pl
>print "test\n";
[snip]
>#!/usr/bin/perly -w
>
>and I get the expected error from bash stating that it cannot find the
>interpreter called "perly"
Indeed I had thought this may have been yet another instance of the
dos vs *nix line endings issue, i.e. due to a spurious carriage
return. But this seems not to be the case at least at a first test on
Linux system:
$ cat -A foo.pl
#!/usr/bin/perl -w^M$
^M$
print "test\n";^M$
^M$
$ ./foo.pl
test
On your system things may actually be different.
>Any ideas?
Other than this... no, sorry!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 11 Oct 2006 16:42:28 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Standard output problem
Message-Id: <111020061642285862%jgibson@mail.arc.nasa.gov>
In article <1160598910.311902.207580@h48g2000cwc.googlegroups.com>,
<wesphillips@gmail.com> wrote:
> I have a perl script, it is very basic:
>
> #!/usr/bin/perl -w
> #test.pl
> print "test\n";
>
>
> The test.pl file is executable (permissions are 755). If I run this
> script like this:
> perl ./test.pl
>
> I get the expected output, but if I run it like this:
>
> ./test.pl
>
> I don't get anything at all. I have induced errors into the script to
> see if I get the error messages, but I still get nothing. If I run the
> script with the errors by explicitly calling perl, I see the error
> output like I expect to. I have a second script in the same directory
> that DOES work when called directly, so I don't know what could be
> wrong. I have also changed the first line so that it looks like this:
>
> #!/usr/bin/perly -w
>
> and I get the expected error from bash stating that it cannot find the
> interpreter called "perly"
>
> Any ideas?
Two. 1) What does 'which perl' return? 2) Try changing the name to
something other than test.pl. 'test' is a shell built-in, and although
./test.pl shouldn't be interpreted as the built-in, you never know (I
have been burned a few times by building a program called 'test').
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
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 9834
***************************************