[30540] in Perl-Users-Digest
Perl-Users Digest, Issue: 1783 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 10 11:09:45 2008
Date: Sun, 10 Aug 2008 08:09:08 -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 Sun, 10 Aug 2008 Volume: 11 Number: 1783
Today's topics:
Backreferences: alias vs copy <mjcarman@mchsi.com>
Re: FAQ 4.70 How can I use a reference as a hash key? <brian.d.foy@gmail.com>
Re: FAQ 4.70 How can I use a reference as a hash key? <ben@morrow.me.uk>
Re: FAQ 4.70 How can I use a reference as a hash key? xhoster@gmail.com
Re: FAQ 4.70 How can I use a reference as a hash key? <rvtol+news@isolution.nl>
Re: FAQ 4.70 How can I use a reference as a hash key? <mjcarman@mchsi.com>
Re: FAQ 5.6 How do I make a temporary file name? <mjcarman@mchsi.com>
HOW CAN WE FOUND ALL PEOPLE abowamar_2001@yahoo.com
How to catch refs to nonexistent sub names at compilati <iler.ml@gmail.com>
Re: How to catch refs to nonexistent sub names at compi <Peter@PSDT.com>
modifying the haystack string inside while($haystack =~ <iler.ml@gmail.com>
Re: modifying the haystack string inside while($haystac <mjcarman@mchsi.com>
Re: modifying the haystack string inside while($haystac <benkasminbullock@gmail.com>
new CPAN modules on Sun Aug 10 2008 (Randal Schwartz)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 10 Aug 2008 15:04:13 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Backreferences: alias vs copy
Message-Id: <NrDnk.237364$TT4.209263@attbi_s22>
In a separate thread someone recently asked what happens if they modify
the variable in a 'while ($var =~ /pattern/g)' loop. In crafting a
sample program I noticed something that surprised me a little:
my $s = 'abc';
while ($s =~ /(\w)/g) {
print "$1 - ";
$s = 'xyz' if $1 eq 'b';
print "$1\n";
}
__END__
a - a
b - y
x - x
y - y
z - z
In the second result, you can see that the value of $1 changes after
reassigning $s. Its value becomes the text from the new string at the
position corresponding to the match against the old one. This makes it
pretty clear that $1 is actually an alias instead of a copy but I can't
find this documented anywhere.
That made me wonder what would happen if the new string was shorter than
the match position in the old one. Consider
my $s = 'abc';
while ($s =~ /(\w)/g) {
print "$1 - ";
$s = 'x' if $1 eq 'c';
print "$1\n";
}
__END__
a - a
b - b
c - c # <--
x - x
as well as:
my $s = 'abc';
while ($s =~ /(\w)/g) {
print "$1 - ";
$s = 'xy' if $1 eq 'c';
print "$1\n";
}
__END__
a - a
b - b
c - # <--
x - x
y - y
If that doesn't scream "NUL terminated C string!" I don't know what does.
Is this documented anywhere, preferably with a caveat about using $1 and
kin after you've changed the match string?
-mjc
------------------------------
Date: Sat, 09 Aug 2008 13:38:34 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.70 How can I use a reference as a hash key?
Message-Id: <090820081338349074%brian.d.foy@gmail.com>
In article <br40n5-0f3.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
<ben@morrow.me.uk> wrote:
> Quoth PerlFAQ Server <brian@stonehenge.com>:
> >
> > 4.70: How can I use a reference as a hash key?
> >
> > (contributed by brian d foy)
> > Hash keys are strings, so you can't really use a reference as the key.
> > When you try to do that, perl turns the reference into its stringified
> > form (for instance, "HASH(0xDEADBEEF)"). From there you can't get back
> > the reference from the stringified form, at least without doing some
> > extra work on your own. Also remember that hash keys must be unique, but
> > two different variables can store the same reference (and those
> > variables can change later).
> I guess this last sentence is meant to cover the case where a variable
> goes out of scope, and a different variable is then allocated at the
> same address?
I don't think that's what I meant. I don't know enough internals to
mean something like that. Would a completely different variable that
got the same address be available through the hash value? That seems
pretty twisted to me if so.
------------------------------
Date: Sat, 9 Aug 2008 19:58:44 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 4.70 How can I use a reference as a hash key?
Message-Id: <4061n5-6pt.ln1@osiris.mauzo.dyndns.org>
Quoth brian d foy <brian.d.foy@gmail.com>:
> In article <br40n5-0f3.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
> <ben@morrow.me.uk> wrote:
>
> > Quoth PerlFAQ Server <brian@stonehenge.com>:
> > >
> > > 4.70: How can I use a reference as a hash key?
> > >
> > > (contributed by brian d foy)
>
> > > Hash keys are strings, so you can't really use a reference as the key.
> > > When you try to do that, perl turns the reference into its stringified
> > > form (for instance, "HASH(0xDEADBEEF)"). From there you can't get back
> > > the reference from the stringified form, at least without doing some
> > > extra work on your own. Also remember that hash keys must be unique, but
> > > two different variables can store the same reference (and those
> > > variables can change later).
>
> > I guess this last sentence is meant to cover the case where a variable
> > goes out of scope, and a different variable is then allocated at the
> > same address?
>
> I don't think that's what I meant.
OK; then what you meant isn't clear, I'm afraid :).
> I don't know enough internals to
> mean something like that. Would a completely different variable that
> got the same address be available through the hash value? That seems
> pretty twisted to me if so.
If you write something like
my %h;
sub foo { $h{$_[0]}++ }
for (1..2) {
foo [];
}
then the hash only gets one entry with value 2 instead of two with value
1. Obviously you can never get two variables with the same address
existing *at the same time* (if you'd kept a reference to the [] that
existed outside the loop, the second iteration would produce an anon
array at a different address), so this is sort-of a further consequence
of the entries in the hash not being garbage-collected.
Hash::Util::Fieldhash handles all this, as well as handling threads,
that's rather the point :), so I think it deserves a mention in this
entry. It's a shame it doesn't work without 5.10.
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *
------------------------------
Date: 10 Aug 2008 02:24:35 GMT
From: xhoster@gmail.com
Subject: Re: FAQ 4.70 How can I use a reference as a hash key?
Message-Id: <20080809222438.697$m4@newsreader.com>
brian d foy <brian.d.foy@gmail.com> wrote:
> In article <br40n5-0f3.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
> <ben@morrow.me.uk> wrote:
>
> > Quoth PerlFAQ Server <brian@stonehenge.com>:
> > >
> > > 4.70: How can I use a reference as a hash key?
> > >
> > > (contributed by brian d foy)
>
> > > Hash keys are strings, so you can't really use a reference as the
> > > key. When you try to do that, perl turns the reference into its
> > > stringified form (for instance, "HASH(0xDEADBEEF)"). From there
> > > you can't get back the reference from the stringified form, at
> > > least without doing some extra work on your own. Also remember
> > > that hash keys must be unique, but two different variables can
> > > store the same reference (and those variables can change later).
>
> > I guess this last sentence is meant to cover the case where a variable
> > goes out of scope, and a different variable is then allocated at the
> > same address?
>
> I don't think that's what I meant. I don't know enough internals to
> mean something like that. Would a completely different variable that
> got the same address be available through the hash value? That seems
> pretty twisted to me if so.
If the original reference is stored in a subsidiary data structure (like
Tie::RefHash does), then that subsidiary structure keeps an active
reference to it so its address can't get re-used. If they aren't using
RefHash, then I don't know what it is that they are doing or what the
consequences might be.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Sun, 10 Aug 2008 14:09:58 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: FAQ 4.70 How can I use a reference as a hash key?
Message-Id: <g7msv1.1p0.1@news.isolution.nl>
Ben Morrow schreef:
> 1. Obviously you can never get two variables with the same address
> existing *at the same time*
In Perl there are many ways to alias a variable. Examples:
$ perl -Mstrict -Mwarnings -le'
my @array = qw/a b c/;
$_ eq "b" and $_ = "y" for @array;
print for @array;
'
a
y
c
$ perl -Mstrict -Mwarnings -MData::Alias -le'
my @array = qw/a b c/;
alias my $x = $array[1];
$x = "z";
print for @array;
'
a
z
c
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sun, 10 Aug 2008 14:15:07 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: FAQ 4.70 How can I use a reference as a hash key?
Message-Id: <LJCnk.291913$yE1.170142@attbi_s21>
brian d foy wrote:
> Would a completely different variable that got the same address be
> available through the hash value? That seems pretty twisted to me if
> so.
I don't think so. The question only addresses the hash key, not the
value (which could be anything). In any event, the memory wouldn't be
reused if there were any lingering references to it.
In theory, a different variable might be available through the key if
the memory used by the original referent was reallocated and you managed
to undo the stringification. If you know enough to do *that* you should
understand that you're juggling flaming chainsaws and not be surprised
if (when) things go horribly wrong.
-mjc
------------------------------
Date: Sun, 10 Aug 2008 14:21:25 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: FAQ 5.6 How do I make a temporary file name?
Message-Id: <FPCnk.291922$yE1.180223@attbi_s21>
PerlFAQ Server wrote:
> 5.6: How do I make a temporary file name?
>
> If you don't need to know the name of the file, you can use "open()"
> with "undef" in place of the file name.
This should probably contain a caveat that it requires Perl 5.8+
Quite a few of the FAQ entries implicitly assume that they're being read
locally and thus have the necessary version of perl available. Between
postings here and online versions this isn't a safe assumption.
-mjc
------------------------------
Date: Sun, 10 Aug 2008 00:11:43 -0700 (PDT)
From: abowamar_2001@yahoo.com
Subject: HOW CAN WE FOUND ALL PEOPLE
Message-Id: <911d0d7a-ee21-4f0d-9b44-cf648c889b1d@f36g2000hsa.googlegroups.com>
FOR A GOOD TIME CAN WE SEE ALL THING ITS RIGHT BUT WE CANN'T GET
THAT .
YASIN OMRAN ALI ISMAIL.
------------------------------
Date: Sun, 10 Aug 2008 00:20:45 -0700 (PDT)
From: Yakov <iler.ml@gmail.com>
Subject: How to catch refs to nonexistent sub names at compilation time ?
Message-Id: <70370a95-d72f-468f-b09f-bd0909dcead6@i76g2000hsf.googlegroups.com>
I use 'usr strict; use warnings'. It catches uses of nonexistent
variables,
at compile time, very good. But it does not catch uses of nonexistent
subroutines
at compile time. Until error at runtime. Too late.
Is there any directive to catch uses of nonexistent subroutines at
compile-time ?
Example:
perl -e 'use strict; use warnings; if(int(rand(2)))
{ NoSuchSub(); }'
Depending on your luck, this program either works, or dies.
But I'd like to catch ref to apparently nonexistent subroutine at
compile-time.
Thanks
Y.L.
------------------------------
Date: Sun, 10 Aug 2008 13:22:16 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: How to catch refs to nonexistent sub names at compilation time ?
Message-Id: <pan.2008.08.10.13.22.15.612204@PSDT.com>
On Sun, 10 Aug 2008 00:20:45 -0700, Yakov wrote:
> But I'd like to catch ref to apparently nonexistent subroutine at
> compile-time.
The reason this hasn't been done is that in general, it is impossible.
Try doing it for this code:
chomp(my $sub = <STDIN>);
$sub->(42);
sub foo { print shift }
What subroutine does $sub refer to? So this is only possible by ignoring
the possibility of dynamically constructed subroutine references. And
doing it for method calls is hair raising.
However, there is a discussion about it over in comp.lang.perl.modules at
the moment; you might drop in on that and see whether something gets
released.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Sun, 10 Aug 2008 00:25:43 -0700 (PDT)
From: Yakov <iler.ml@gmail.com>
Subject: modifying the haystack string inside while($haystack =~ /needle/g) { ... }
Message-Id: <cb0c9804-c606-4d22-b2bb-bb722ff2ecd3@m73g2000hsh.googlegroups.com>
What exactly happens if I modify the $haystack inside such while (see
subject) ?
I realize that "don't do this" is good answer, and , but still, I am
cusious
know what happens if $haystack is modified (nobody does it
conciensly).
I see two-three possibilities
(1) matching position is reset to 0
(2) matching position remains where it was.
(3) next match is forced to fail
... (4) warning is printed ... (5) program dies
Just curious
Y.L.
------------------------------
Date: Sun, 10 Aug 2008 14:39:01 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: modifying the haystack string inside while($haystack =~ /needle/g) { ... }
Message-Id: <94Dnk.237336$TT4.183282@attbi_s22>
Yakov wrote:
> What exactly happens if I modify the $haystack inside such while
> (see subject) ?
Code from subject [please don't put it there]:
while($haystack =~ /needle/g) { ... }
It's fine to modify the variable in a while loop. In your case, it would
reset the match.
my $s = 'abc';
while ($s =~ /(\w)/g) {
print "$1\n";
$s = 'xyz' if $1 eq 'b';
}
__END__
a
b
x
y
z
There are caveats about modifying an array/list/hash while iterating
over it, but those don't apply here.
-mjc
------------------------------
Date: Sun, 10 Aug 2008 10:00:44 +0200 (CEST)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: modifying the haystack string inside while($haystack =~ /needle/g) { ... }
Message-Id: <g7m77c$smn$1@aioe.org>
On Sun, 10 Aug 2008 00:25:43 -0700, Yakov wrote:
> What exactly happens if I modify the $haystack inside such while (see
> subject) ?
It would be easier to reply to your message if you didn't put part of
it into the subject like that.
Anyway, "while" just tests for true or false, so of course you can change
$haystack as much as you like inside the loop.
------------------------------
Date: Sun, 10 Aug 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Aug 10 2008
Message-Id: <K5DBqL.16Bz@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Acme-Acotie-0.02
http://search.cpan.org/~yappo/Acme-Acotie-0.02/
Crash of Namespace
----
Activator-0.9
http://search.cpan.org/~knassar/Activator-0.9/
Development Framework - Object Oriented framework to ease creation and rapid development of multi-developer distributed mixed environment perl based software projects, especially Catalyst based websit
----
Activator-0.90
http://search.cpan.org/~knassar/Activator-0.90/
Development Framework - Object Oriented framework to ease creation and rapid development of multi-developer distributed mixed environment perl based software projects, especially Catalyst based websit
----
CDB_Perl-0.53
http://search.cpan.org/~plank/CDB_Perl-0.53/
Perl extension for reading and creating CDB files
----
CatalystX-ListFramework-Builder-0.17
http://search.cpan.org/~oliver/CatalystX-ListFramework-Builder-0.17/
Instant AJAX web front-end for DBIx::Class, using Catalyst
----
Chart-Gnuplot-0.04
http://search.cpan.org/~kwmak/Chart-Gnuplot-0.04/
Plot graph using Gnuplot on the fly
----
Devel-GlobalDestruction-0.01
http://search.cpan.org/~nuffin/Devel-GlobalDestruction-0.01/
Expose PL_dirty, the flag which marks global destruction.
----
Devel-GlobalDestruction-0.02
http://search.cpan.org/~nuffin/Devel-GlobalDestruction-0.02/
Expose PL_dirty, the flag which marks global destruction.
----
Device-Gsm-1.49
http://search.cpan.org/~cosimo/Device-Gsm-1.49/
Perl extension to interface GSM phones / modems
----
GD-SVG-0.29
http://search.cpan.org/~twh/GD-SVG-0.29/
Seamlessly enable SVG output from scripts written using GD
----
Getopt-Chain-0.001_3
http://search.cpan.org/~rkrimen/Getopt-Chain-0.001_3/
svn- and git-style option and subcommand processing
----
Graphics-Color-0.08
http://search.cpan.org/~gphat/Graphics-Color-0.08/
Device and library agnostic color spaces.
----
HTML-Mail-0.11
http://search.cpan.org/~plank/HTML-Mail-0.11/
Perl extension for sending emails with embedded HTML and media
----
HTTP-Cookies-Mozilla-2.01
http://search.cpan.org/~polettix/HTTP-Cookies-Mozilla-2.01/
Cookie storage and management for Mozilla
----
Helios-Panoptes-1.40
http://search.cpan.org/~lajandy/Helios-Panoptes-1.40/
CGI::Application providing web admin interface to Helios distributed job processing system
----
IPC-Run3-0.042
http://search.cpan.org/~rschupp/IPC-Run3-0.042/
run a subprocess with input/ouput redirection
----
Image-ImageShack-0.03
http://search.cpan.org/~plank/Image-ImageShack-0.03/
Upload images to be hosted at imageshack.us without needing any account information.
----
Jabber-SimpleSend-0.03
http://search.cpan.org/~gmccar/Jabber-SimpleSend-0.03/
Send a Jabber message simply.
----
Log-Log4perl-Appender-ScreenColoredLevels-UsingMyColors-0.10_01
http://search.cpan.org/~bdfoy/Log-Log4perl-Appender-ScreenColoredLevels-UsingMyColors-0.10_01/
Colorize messages according to level amd my colors
----
Mac-CocoaDialog-0.0.2
http://search.cpan.org/~polettix/Mac-CocoaDialog-0.0.2/
script with CocoaDialog
----
MacOSX-Alias-0.10_02
http://search.cpan.org/~bdfoy/MacOSX-Alias-0.10_02/
Read or create Mac OS X aliases
----
Math-Amoeba-0.05
http://search.cpan.org/~tom/Math-Amoeba-0.05/
Multidimensional Function Minimisation
----
Module-Extract-Namespaces-0.12
http://search.cpan.org/~bdfoy/Module-Extract-Namespaces-0.12/
extract the package declarations from a module
----
Module-Extract-VERSION-0.11
http://search.cpan.org/~bdfoy/Module-Extract-VERSION-0.11/
Extract a module version without running code
----
Module-Release-2.00_02
http://search.cpan.org/~bdfoy/Module-Release-2.00_02/
Automate software releases
----
Module-Release-Git-0.10_02
http://search.cpan.org/~bdfoy/Module-Release-Git-0.10_02/
Use Git with Module::Release
----
Net-SCP-Expect-0.14
http://search.cpan.org/~rybskej/Net-SCP-Expect-0.14/
Wrapper for scp that allows passwords via Expect.
----
Net-Squid-Auth-Engine-0.02
http://search.cpan.org/~lmc/Net-Squid-Auth-Engine-0.02/
External Credentials Authentication for Squid HTTP Cache
----
Net-Squid-Auth-Plugin-SimpleLDAP
http://search.cpan.org/~russoz/Net-Squid-Auth-Plugin-SimpleLDAP/
A simple LDAP-based credentials validation plugin for Net::Squid::Auth::Engine
----
Net-Squid-Auth-Plugin-SimpleLDAP-0.01.01
http://search.cpan.org/~russoz/Net-Squid-Auth-Plugin-SimpleLDAP-0.01.01/
A simple LDAP-based credentials validation plugin for Net::Squid::Auth::Engine
----
PAR-0.981_01
http://search.cpan.org/~smueller/PAR-0.981_01/
Perl Archive Toolkit
----
PAR-Repository-Client-0.19_01
http://search.cpan.org/~smueller/PAR-Repository-Client-0.19_01/
Access PAR repositories
----
POE-Component-IRC-Plugin-MegaHAL-0.06
http://search.cpan.org/~hinrik/POE-Component-IRC-Plugin-MegaHAL-0.06/
A PoCo-IRC plugin which provides access to a MegaHAL conversation simulator.
----
Perl-Metrics-Simple-0.11
http://search.cpan.org/~matisse/Perl-Metrics-Simple-0.11/
Count packages, subs, lines, etc. of many files.
----
Pod-SpeakIt-MacSpeech-0.11
http://search.cpan.org/~bdfoy/Pod-SpeakIt-MacSpeech-0.11/
This is the description
----
RSSycklr-0.06
http://search.cpan.org/~ashley/RSSycklr-0.06/
(beta) Highly configurable recycling of syndication (RSS/Atom) feeds into tailored, guaranteed XHTML fragments.
----
RSSycklr-0.07
http://search.cpan.org/~ashley/RSSycklr-0.07/
(beta) Highly configurable recycling of syndication (RSS/Atom) feeds into tailored, guaranteed XHTML fragments.
----
Test-Smoke-1.34
http://search.cpan.org/~abeltje/Test-Smoke-1.34/
The Perl core test smoke suite
----
Titanium-0.90_1
http://search.cpan.org/~markstos/Titanium-0.90_1/
A strong, lightweight web application famework
----
Tree-RB-0.3
http://search.cpan.org/~arunbear/Tree-RB-0.3/
Perl implementation of the Red/Black tree, a type of balanced binary search tree.
----
mpp-5
http://search.cpan.org/~pfeiffer/mpp-5/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
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 V11 Issue 1783
***************************************