[26517] in Perl-Users-Digest
Perl-Users Digest, Issue: 8668 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 15 11:05:40 2005
Date: Tue, 15 Nov 2005 08: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)
Perl-Users Digest Tue, 15 Nov 2005 Volume: 10 Number: 8668
Today's topics:
Re: FAQ 4.69 How can I use a reference as a hash key? <sdn.girths00869@zoemail.net>
Re: FAQ 4.69 How can I use a reference as a hash key? (Anno Siegel)
Re: Getting a list of all current variables in a Perl p <jkeen_via_google@yahoo.com>
Re: Grouping like items together <tadmc@augustmail.com>
Re: Inject fresh variable in scope <tadmc@augustmail.com>
Re: Pattern Matching problem! <francis@nospam.com>
Re: Pattern Matching problem! <tadmc@augustmail.com>
Re: strange problem with system() and backtick operator <news@chaos-net.de>
Re: strange problem with system() and backtick operator <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Nov 2005 07:08:45 -0600
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: FAQ 4.69 How can I use a reference as a hash key?
Message-Id: <Xns970F52F56C3C3sdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
PerlFAQ Server <comdog@pair.com> wrote in
news:dlcf95$59b$1@reader2.panix.com:
> 4.69: 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).
>
> The Tie::RefHash module, which is distributed with perl, might be
> what you want. It handles that extra work.
What is this "extra work"? I have no clue how to get a reference from
a stringified version of it, other than to manually search the symbol
table, or to write some XS code to cheat (which would probably segfault
and/or memory leak).
- --
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32) - WinPT 0.7.96rc1
iD8DBQFDed33Y96i4h5M0egRAgNpAKCmnwDj1jfu/bOeT0iEAL7XwHe9QgCffuwH
qmVb0nc/IC6Q48SnXxYUdEA=
=iTmB
-----END PGP SIGNATURE-----
------------------------------
Date: 15 Nov 2005 14:03:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 4.69 How can I use a reference as a hash key?
Message-Id: <dlcps3$jk3$1@mamenchi.zrz.TU-Berlin.DE>
Eric J. Roode <sdn.girths00869@zoemail.net> wrote in comp.lang.perl.misc:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> PerlFAQ Server <comdog@pair.com> wrote in
> news:dlcf95$59b$1@reader2.panix.com:
>
> > 4.69: 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).
> >
> > The Tie::RefHash module, which is distributed with perl, might be
> > what you want. It handles that extra work.
>
> What is this "extra work"? I have no clue how to get a reference from
> a stringified version of it, other than to manually search the symbol
> table, or to write some XS code to cheat (which would probably segfault
> and/or memory leak).
Presumably Tie::RefHash simply keeps a copy of every reference that
is used as a hash key in an extra hash.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Tue, 15 Nov 2005 12:16:17 GMT
From: James E Keenan <jkeen_via_google@yahoo.com>
Subject: Re: Getting a list of all current variables in a Perl program
Message-Id: <4379D193.9050003@yahoo.com>
John W. Krahn wrote:
> James E Keenan wrote:
>
>>
>>1. Are there any better ways to approach this problem?
>>2. In addition to package variables, how can I get a list of the
>>lexical variables declared at a given point in a program? (I think this
>>means the content of the scratchpad(s)?)
>
>
> perldoc B::Xref
> perldoc B::Showlex
>
Those look helpful and I will check them out today. Thanks, John!
jimk
------------------------------
Date: Tue, 15 Nov 2005 08:48:14 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Grouping like items together
Message-Id: <slrndnjt9e.bu5.tadmc@magna.augustmail.com>
AcCeSsDeNiEd <dillon@SpamMinuSaccessdenied.darktech.org> wrote:
> I'm trying to group the 'similar' files together and place them in a directory.
One step of the solution would be to get them sorted by "name"...
> E.g of such files:
>
> Mike F. 2332445-withdrawal.pdf
> Mike F. 43565654-letter.pdf
> Mike F. 434324.sign.pdf
> Dawn M. Yang letter of acceptance.pdf
> Dawn M. Yang (01).pdf
> Dawn M. Yang 4355434 SOA.pdf
... so your test data should not be already sorted.
> I'm trying to group these files by their names.
Another part of the solution then would be to identify where
the "names" end.
> The names are not in a fixed format.
Then you will need to identify every case so that you can write
code that will handle every case.
> E.g, not all names may have a middle name.
But you identify only one of the cases, and provide none of that one
case in your test data.
Do you also have:
Mike F. Smith 1234.pdf
where you need it to be grouped with " Mike F."?
You make it too hard to help you...
> if these names were in a list, how do I match and group them together?
You need to seperate the "name" from "the rest" to start with.
I will assume that each component of a "name" starts with an
upper case letter, and that the first part after the name
does NOT start with an upper case letter.
If you had lines like the above in a file, then this seems
to do a credible job of identifying the "name" part:
----------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
while ( <> ) {
next unless /^(([A-Z]\S+ )+)/;
chop(my $name = $1);
print "'$name'\n";
}
----------------------------------------
> How would I know the group
> name?
See above.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 14 Nov 2005 23:51:32 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Inject fresh variable in scope
Message-Id: <slrndnitr4.an0.tadmc@magna.augustmail.com>
Andrei Alexandrescu (See Website For Email) <SeeWebsiteForEmail@moderncppdesign.com> wrote:
> Now, the question is: is there a simple way to manage
> dependencies in Perl - i.e., download a package and all of its
> dependents from somewhere?
perldoc CPAN
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 15 Nov 2005 14:56:46 GMT
From: "Francis Sylvester" <francis@nospam.com>
Subject: Re: Pattern Matching problem!
Message-Id: <OGmef.6529$375.1033@fe3.news.blueyonder.co.uk>
> Either you'd better stick to a simple regex, and skip the parsing module,
> or (better) taking advantage of the module you are using, and doing
> something like:
>
> while ( my $token = $parser->get_tag('a') ) {
> if ($token->[1]{href} =~ /$mymatch/) {
> print $parser->get_text('a')."\n";
> }
> }
>
> (I'm not sure if that's what you're looking for, but hopefully you get the
> idea.)
>
Many thanks for all your replies. I'm sorry, I should have been clearer -
the code executes without error messages but I sometimes get unwanted
results in $1. After closer inspection, I think it's because sometimes it's
returning $1 from the earlier pattern match ( if ($token->[1]->{"href"} =~
/$mymatch/) rather than the pattern match I wanted ($document =~
/$searchstring(.+?)someidentifier/;)
Is there a way to reset the value of $1?
Many thanks,
Francis
------------------------------
Date: Tue, 15 Nov 2005 09:52:05 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Pattern Matching problem!
Message-Id: <slrndnk115.c6j.tadmc@magna.augustmail.com>
Francis Sylvester <francis@nospam.com> wrote:
>> if ($token->[1]{href} =~ /$mymatch/) {
> I sometimes get unwanted
> results in $1. After closer inspection, I think it's because sometimes it's
> returning $1 from the earlier pattern match ( if ($token->[1]->{"href"} =~
> /$mymatch/)
Note that that code ensures that the pattern match *succeeded*.
> rather than the pattern match I wanted ($document =~
> /$searchstring(.+?)someidentifier/;)
We don't really know, since you did not quote that part of the code,
but you should always ensure that the match succeeded before
using the dollar-digit variables, so:
Is _your_ pattern match being tested for success?
> Is there a way to reset the value of $1?
Yes. They are reset on every _successful_ pattern match.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 15 Nov 2005 13:28:31 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: strange problem with system() and backtick operator
Message-Id: <slrndnjl3f.5a2.news@maki.homeunix.net>
A. Sinan Unur wrote :
> Let's see:
>
> $mode = '0644'; chmod oct($mode), 'foo'; # this is better
> $mode = 0644; chmod $mode, 'foo'; # this is best
>
> Why not use the best method?
Hello Sinan,
I used oct($mode) because I get $mode from a sub which returns a three
(or less) digit decimal number. The number is parsed and calculated from
a ftp directory listing.
I asumed that the last method is best, because $mode is initialized
allready with an octal value.
If I have a decimal value I thought I'd have to convert it to octal.
If I am wrong or if there is a better method to do so, please let me
know.
Regards
Martin
--
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'
------------------------------
Date: Tue, 15 Nov 2005 14:01:18 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: strange problem with system() and backtick operator
Message-Id: <Xns970F5BC66978Easu1cornelledu@127.0.0.1>
Martin Kissner <news@chaos-net.de> wrote in
news:slrndnjl3f.5a2.news@maki.homeunix.net:
> A. Sinan Unur wrote :
>
>> Let's see:
>>
>> $mode = '0644'; chmod oct($mode), 'foo'; # this is better
>> $mode = 0644; chmod $mode, 'foo'; # this is best
>>
>> Why not use the best method?
>
> Hello Sinan,
>
> I used oct($mode) because I get $mode from a sub which returns a three
> (or less) digit decimal number. The number is parsed and calculated
> from a ftp directory listing.
>
> I asumed that the last method is best, because $mode is initialized
> allready with an octal value. If I have a decimal value I thought I'd
> have to convert it to octal.
perldoc -f oct
oct EXPR
oct Interprets EXPR as an octal string and returns the
corresponding value.
Notice the "octal string".
A number is just a number, that is it.
#!/usr/bin/perl
use strict;
use warnings;
my $x = 64;
my $y = 0100;
my $z = '0100';
print "x = $x", "\n";
print 'oct(x) = ', oct($x), "\n";
print "y = $y\n";
print 'oct(y) = ', oct($y), "\n";
print "z = $z\n";
print 'oct(z) = ', oct($z), "\n";
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
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 8668
***************************************