[25132] in Perl-Users-Digest
Perl-Users Digest, Issue: 7381 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 9 06:05:50 2004
Date: Tue, 9 Nov 2004 03:05:10 -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, 9 Nov 2004 Volume: 10 Number: 7381
Today's topics:
'stat' and it's exceptions <fred@no##!$%regex.com>
Re: 'stat' and it's exceptions <bik.mido@tiscalinet.it>
Activestate Perl 5.6 ppm <g-preston1@ti.com>
Re: Activestate Perl 5.6 ppm <g-preston1@ti.com>
Re: Activestate Perl 5.6 ppm <kalinaubears@iinet.net.au>
Re: Activestate Perl 5.6 ppm <g-preston1@ti.com>
Re: cgi question <flavell@ph.gla.ac.uk>
Re: Check POP3 E-mail <jwkenne@attglobal.net>
Re: Extract a number from a string. <ineverreadanythingsenttome@hotmail.com>
FAQ 8.34: I {changed directory, modified my environment <comdog@panix.com>
FAQ 9.20: How do I send mail? <comdog@panix.com>
finding ethernet interfaces and IPs <zebee@zip.com.au>
Re: finding ethernet interfaces and IPs <zebee@zip.com.au>
Re: finding ethernet interfaces and IPs <1usa@llenroc.ude.invalid>
Re: finding ethernet interfaces and IPs <someone@example.com>
Finding two strings with the same crc32 <dzluk8fsxsw0001@sneakemail.com>
Re: Grabbing a PDF file from the web...how? <nospam@bigpond.com>
How to save/restore a hash of hashes? <ineverreadanythingsenttome@hotmail.com>
Re: How to save/restore a hash of hashes? (Anno Siegel)
Re: How to save/restore a hash of hashes? <ineverreadanythingsenttome@hotmail.com>
Re: matching all perldoc names but no more <ioneabu@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 08 Nov 2004 20:24:08 -0600
From: Fred aka.... Fred <fred@no##!$%regex.com>
Subject: 'stat' and it's exceptions
Message-Id: <a990p0p3n0mci0ibuslbgfi997h0b18hlu@4ax.com>
This line is all the deal.
my(%times) =
map{$_,(stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,readdir(DIR));
# [9] gets the mod time.
#Sorry my client is wrapping to 80 lines the line above is on 1 line
#The above line when placed in context of:
my(%times) = map {$_, (stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,
readdir(DIR));
#why can't we just stat a $pattern and not everything????
my $key;
foreach $key(keys %times)
{ my $inkey = substr($key,0,8);
if ($inkey =~ /^\./g) { $inkey =~ s/\.//g;} # fixs .xxx
if ($inkey !~ /$pattern/) { #HAS TO match the
pattern
delete $times{$key}; #AND REMOVE IT IF NOT
}
else
{
$file_name = $key; # bingo!
}
}
Sorry as hell for all the wrapping, normally I use Pan but I'm stuck
in windows tonight.
I'm trying notepad.exe but it might have mangled on the post.
Caveat emptor.
My question is this:
my(%times) = map {$_, (stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,
readdir(DIR))
The part of the grep loading the values, the keys are the times... I
dont' know much about this:
grep(!/^\.{1,2}$/, readdir(DIR))
and no faq refs please, I KNOW it's in the faqs (?), I just want some
help here. If that honesty isn't good enought then I don't qualify.
For CLPM.
I know the grep loads everything. Now coming from a Unix BG I figure
those {1,2}$/, references might be changed to
grep a pattern of $pattern..... but the stuff I don't know is
1. How to expand the var in that context.
2. What 1,2 mean (please don't tell me RTFM.. I ready got code
running, just want to understand perl.)
3. Did I say TIA?
TIA
Fred, aka Fred
------------------------------
Date: Tue, 09 Nov 2004 09:15:47 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: 'stat' and it's exceptions
Message-Id: <jqu0p0lt3gs5lgr8glekva5i1mcv6nupa2@4ax.com>
On Mon, 08 Nov 2004 20:24:08 -0600, Fred aka.... Fred
<fred@no##!$%regex.com> wrote:
>My question is this:
>
>
>
>my(%times) = map {$_, (stat("$dir/$_"))[9]}grep(!/^\.{1,2}$/,
>readdir(DIR))
[snip]
>grep(!/^\.{1,2}$/, readdir(DIR))
it is a (clumsy) means to exclude '.' and '..'.
All in all you probably want to use
glob '*' # if in CWD
or
glob '/path/to/dir/*'
instead.
>2. What 1,2 mean (please don't tell me RTFM.. I ready got code
>running, just want to understand perl.)
Err... RTFM! Hey, at least I'm pointing you to the relevant portion of
it:
perldoc perlre
Hint: 1,2 hardly means anything, but {1,2} does and is a quantifier.
Wether or not you already got code running, the place to look in to
*understand perl* is generally TFM.
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: Mon, 8 Nov 2004 23:32:58 -0600
From: "Jerry Preston" <g-preston1@ti.com>
Subject: Activestate Perl 5.6 ppm
Message-Id: <cmpkqb$lck$1@home.itg.ti.com>
I am trying to add the ppm DBI for ActiveState Perl v5.6.1 for
sun-polaris-thread-multi server. I need to be able to access ORACLE data
base, but I can only find DBI for 5.8. When I do ppm install DBI it get the
following:
.... it is not for this build of Perl.
I have looked all over the ActiveState web site and I can not find it. I
know it is right in front of me, but I cannot find it.
Where to look?
Thanks,
Jerry
------------------------------
Date: Tue, 9 Nov 2004 02:59:23 -0600
From: "Jerry Preston" <g-preston1@ti.com>
Subject: Re: Activestate Perl 5.6 ppm
Message-Id: <cmq0tc$7s$1@home.itg.ti.com>
OK! I have tried to "ppm search dbi" and I cannot get the firewall. Where
can I find it to ftp/copy?
Jerry
"Jerry Preston" <g-preston1@ti.com> wrote in message
news:cmpkqb$lck$1@home.itg.ti.com...
> I am trying to add the ppm DBI for ActiveState Perl v5.6.1 for
> sun-polaris-thread-multi server. I need to be able to access ORACLE data
> base, but I can only find DBI for 5.8. When I do ppm install DBI it get
the
> following:
>
> .... it is not for this build of Perl.
>
> I have looked all over the ActiveState web site and I can not find it. I
> know it is right in front of me, but I cannot find it.
>
> Where to look?
>
> Thanks,
>
> Jerry
>
>
------------------------------
Date: Tue, 09 Nov 2004 09:40:12 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Activestate Perl 5.6 ppm
Message-Id: <419091c9$0$6555$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Jerry Preston wrote:
> OK! I have tried to "ppm search dbi" and I cannot get the firewall. Where
> can I find it to ftp/copy?
>
If you open your perl/html/index.html file in a browser, click on the
link to the 'PerlPackageManager', then click on the link to 'PPM,
Proxies and Firewalls' you'll find out how to get around the 'firewall'
issue.
Otherwise, the files can be downloaded from somewhere on the AS website
- but I no longer have a link.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Tue, 9 Nov 2004 04:53:56 -0600
From: "Jerry Preston" <g-preston1@ti.com>
Subject: Re: Activestate Perl 5.6 ppm
Message-Id: <cmq7k4$475$1@home.itg.ti.com>
Rob,
I have tried the proxy trick and it still does not work.
Thanks,
Jerry
"Sisyphus" <kalinaubears@iinet.net.au> wrote in message
news:419091c9$0$6555$5a62ac22@per-qv1-newsreader-01.iinet.net.au...
> Jerry Preston wrote:
> > OK! I have tried to "ppm search dbi" and I cannot get the firewall.
Where
> > can I find it to ftp/copy?
> >
>
> If you open your perl/html/index.html file in a browser, click on the
> link to the 'PerlPackageManager', then click on the link to 'PPM,
> Proxies and Firewalls' you'll find out how to get around the 'firewall'
> issue.
>
> Otherwise, the files can be downloaded from somewhere on the AS website
> - but I no longer have a link.
>
> Cheers,
> Rob
>
>
> --
> To reply by email u have to take out the u in kalinaubears.
>
------------------------------
Date: Mon, 8 Nov 2004 23:40:33 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: cgi question
Message-Id: <Pine.LNX.4.61.0411082324240.17835@ppepc56.ph.gla.ac.uk>
On Mon, 8 Nov 2004, Bryan Williams wrote:
> This is probably OT,
What would stand you in good stead, with problems of this nature,
would be to give some attention to the partitioning of your problem
space.
If you're having trouble with the (supposedly)-HTML extruded by some
executable code, then for heaven's sake grab a copy of that extruded
stuff and look at it more closely - get the executable program out of
the way - and ask the question (if there's still one to ask, once
you've looked at the extrusion) in a place where HTML and browsers are
on-topic.
Once you know what HTML you want/need to do that job, we can discuss
the details of how to write the program that's meant to produce it.
Specific hint: feed that extrusion to an HTML validator, e.g the one
at the W3C.
> I am trying to update some old Perl cgi scripts.
I've got some scripts that look little better than that, written in
the mid-1990s: I wouldn't care to expose them here, and when they come
up for any kind of "updating" I've resolved to do what I'm about to
suggest to you. It rather looks as if you'd be better off to
re-engineer them, in the sense of tossing out the old junk, reviewing
what's needing to be done, and writing a new one from scratch to do
it, using recent Perl techniques.
Others have already commented on some of those details. But I can't
resist repeating that the clue to solving complex problems is to
partition them into reasonably self-contained parts, and seek advice
(where the act of partitioning the problem hasn't already exposed the
clue, which I find myself is often the case) with each part, in the
place where that part is on-topic.
If you haven't noticed that this group collectively doesn't welcome
questions that are basically about CGI, or HTML, and only incidentally
involve Perl, then maybe you haven't been reading the group for long
enough to really get the benefit out of it that you could.
good luck.
------------------------------
Date: Tue, 09 Nov 2004 00:56:24 GMT
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: Check POP3 E-mail
Message-Id: <YAUjd.47835$fF6.20238166@news4.srv.hcvlny.cv.net>
Jim Gibson wrote:
> This is off-topic for a Perl NG, but you brought it up, and I feel the
> need to correct this misinformation. That would indeed be an Urban
> Legend. I have programmed in both Ada (many years ago) and C++ (for the
> past 9 years) and IMHO Ada is no where near as complex as C++. The
> reference manual for Ada 83 is 330 pages, and that includes 20 pages on
> Tasks, which Ada has built-in and C++ does not. Ada 95 added many more
> features, but they are all optional and backwards compatible with Ada
> 83. (I do not have an Ada 95 reference manual.)
Another reason for complexity in Ada is that Ada, PL/I, and Java are
just about the only important languages with strictly defined semantics
(Java's only as a product of the JavaVM). The complexities of Ada weigh
far more on the writer of an Ada compiler or an Ada RTL than they do on
an Ada programmer.
--
John W. Kennedy
"Only an idiot fights a war on two fronts. Only the heir to the throne
of the kingdom of idiots would fight a war on twelve fronts"
-- J. Michael Straczynski. "Babylon 5", "Ceremonies of Light and Dark"
------------------------------
Date: Tue, 9 Nov 2004 01:42:33 -0800
From: "David Filmer" <ineverreadanythingsenttome@hotmail.com>
Subject: Re: Extract a number from a string.
Message-Id: <_8Sdnf827_Z6DA3cRVn-gA@comcast.com>
Out of curiosity, are you trying to parse the output from IBM's LUM
(i4lls/i4blt) license manager?
"Adam" <adam_cheney@hotmail.com> wrote in message
news:214d0889.0411080240.23a9c5bc@posting.google.com...
> Hi All,
>
> Apologies if this is laughably simple, but it's been a long time since
> I've used Perl, and I seem to suffer from Homer Simpson's problem:
> every time I learn something new, it pushes old stuff out.
>
> I'm trying to extract a number from a line of text returned by a
> license-checking command. I open a pipe to the command, and read
> through each line that is returned. When I find the text "Maximum..."
> or "Current..." I want to extract and store the number in that line. I
> tried using something like this to start with:
>
> $lic_usage{$lic_type}{$max} = /\d+/ if (/Maximum/);
> $lic_usage{$lic_type}{$cur} = /\d+/ if (/Current/);
>
> Of course, this only stores a 1 ('True') when it finds the string, and
> I want it to record the actual digits.
>
> Help!
>
> Cheers - Adam...
------------------------------
Date: Tue, 9 Nov 2004 05:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 8.34: I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?
Message-Id: <cmpj25$dd1$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
8.34: I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?
Unix
In the strictest sense, it can't be done--the script executes as a
different process from the shell it was started from. Changes to a
process are not reflected in its parent--only in any children
created after the change. There is shell magic that may allow you to
fake it by eval()ing the script's output in your shell; check out
the comp.unix.questions FAQ for details.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Tue, 9 Nov 2004 11:03:05 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 9.20: How do I send mail?
Message-Id: <cmq859$ipf$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
9.20: How do I send mail?
Use the "sendmail" program directly:
open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
or die "Can't fork for sendmail: $!\n";
print SENDMAIL <<"EOF";
From: User Originating Mail <me\@host>
To: Final Destination <you\@otherhost>
Subject: A relevant subject line
Body of the message goes here after the blank line
in as many lines as you like.
EOF
close(SENDMAIL) or warn "sendmail didn't close nicely";
The -oi option prevents sendmail from interpreting a line consisting of
a single dot as "end of message". The -t option says to use the headers
to decide who to send the message to, and -odq says to put the message
into the queue. This last option means your message won't be immediately
delivered, so leave it out if you want immediate delivery.
Alternate, less convenient approaches include calling mail (sometimes
called mailx) directly or simply opening up port 25 have having an
intimate conversation between just you and the remote SMTP daemon,
probably sendmail.
Or you might be able use the CPAN module Mail::Mailer:
use Mail::Mailer;
$mailer = Mail::Mailer->new();
$mailer->open({ From => $from_address,
To => $to_address,
Subject => $subject,
})
or die "Can't open: $!\n";
print $mailer $body;
$mailer->close();
The Mail::Internet module uses Net::SMTP which is less Unix-centric than
Mail::Mailer, but less reliable. Avoid raw SMTP commands. There are many
reasons to use a mail transport agent like sendmail. These include
queuing, MX records, and security.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Tue, 09 Nov 2004 03:51:17 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: finding ethernet interfaces and IPs
Message-Id: <slrncp0f7t.h1t.zebee@zeus.zipworld.com.au>
I have a machine with more than one ethernet interface, and several
IP's aliased to the interfaces.
And several machines with aliases but only one interface.
So I don't want to hardcode interface names like eth0 into anything.
I want a list of IP addresses on the machine and the interface each IP
lives on.
I've been using grep and awk on the output from ifconfig -a to get the
IPs for use in a shellscript, but the new interface has kyboshed that as
ifconfig puts the interface name and IP address on different lines.
So I thought I should write a short perlscript to produce the
information for the shellscript.
Is there a module I can use to get the information, or will I have to
OPEN an ifconfig pipe and parse what I get from that? I'm trying to
avoid shell calls in perl if I can.
I've searched on CPAN but couldn't find anything that understood both
interface and IP.
Zebee
--
Zebee Johnstone (zebee@zip.com.au), proud holder of
aus.motorcycles Poser Permit #1.
"Motorcycles are like peanuts... who can stop at just one?"
------------------------------
Date: Tue, 09 Nov 2004 04:15:59 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: finding ethernet interfaces and IPs
Message-Id: <slrncp0gm8.ibk.zebee@zeus.zipworld.com.au>
In comp.lang.perl.misc on Tue, 09 Nov 2004 03:51:17 GMT
Zebee Johnstone <zebee@zip.com.au> wrote:
>
> I've searched on CPAN but couldn't find anything that understood both
> interface and IP.
as a followup, I did (afer I posted this of course) find Net::Interface
and Net::Ifconfig:Wrapper, but neither would compile on my system.
This may indicate I'm missing a library, but I've no idea how to find
which one. As far as I know it's pretty complete.
Zebee
------------------------------
Date: 9 Nov 2004 04:17:14 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: finding ethernet interfaces and IPs
Message-Id: <Xns959BECE605FE5asu1cornelledu@132.236.56.8>
Zebee Johnstone <zebee@zip.com.au> wrote in
news:slrncp0f7t.h1t.zebee@zeus.zipworld.com.au:
> I have a machine with more than one ethernet interface, and several
> IP's aliased to the interfaces.
...
> Is there a module I can use to get the information, or will I have to
> OPEN an ifconfig pipe and parse what I get from that? I'm trying to
> avoid shell calls in perl if I can.
>
> I've searched on CPAN but couldn't find anything that understood both
> interface and IP.
http://search.cpan.org/search?query=network+interface&mode=all
returns
http://search.cpan.org/~lds/IO-Interface-0.98/Interface.pm
Does that help?
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Tue, 09 Nov 2004 08:31:20 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: finding ethernet interfaces and IPs
Message-Id: <sf%jd.134301$df2.35632@edtnps89>
Zebee Johnstone wrote:
> I have a machine with more than one ethernet interface, and several
> IP's aliased to the interfaces.
>
> And several machines with aliases but only one interface.
>
> So I don't want to hardcode interface names like eth0 into anything.
>
> I want a list of IP addresses on the machine and the interface each IP
> lives on.
>
> I've been using grep and awk on the output from ifconfig -a to get the
> IPs for use in a shellscript, but the new interface has kyboshed that as
> ifconfig puts the interface name and IP address on different lines.
If your ifconfig output is the same as mine then this should be close to what
you need:
ifconfig -a | perl -l -00ne'print/^(\w+\s).+?inet addr:([\d.]+)/s'
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 9 Nov 2004 11:04:38 +0100
From: "Jonas Nilsson" <dzluk8fsxsw0001@sneakemail.com>
Subject: Finding two strings with the same crc32
Message-Id: <cmq4na$5qm$1@news.island.liu.se>
Just for fun I would like to find two strings that have the same crc32. The
probably of doing this for a set of for example one million strings is more
than 99.9999999999999999999999999999999999999999999999997%.
To calculate the chance of $n strings leading to all different crc32 is done
by this code: (assuming randomly distributed crc32 values)
use strict;
my $tmp=1;
my $n=1000000;
my $ant=2**32;
for (0..$n) {
$tmp*=($ant-$_)/$ant;
print "$_\t$tmp\n" unless ($_%10000);
}
If I try to find two string that give the same crc32 however I don't
succeed. I use the code below to spot strings that have the same first 28
bits (to save memory I don't store all 32 bits). The code don't find any
however even after checking 6 million strings!
Why?
Sorry for being a bit off topic.
use strict;
use Digest::CRC qw(crc32);
my $string='aaaaa';
$|=1;
my $v;
for (0..11881375) {
unless ($_%100000) {
print "$_\t",length($v),"\n";
}
my $tmp=crc32($string)>>4;
if (vec($v,$tmp,1)) {
print "$string\n";
}
vec($v,$tmp,1)=1;
$string++;
}
/jN
------------------------------
Date: Tue, 09 Nov 2004 11:48:55 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Grabbing a PDF file from the web...how?
Message-Id: <2vam08F2hs2k1U2@uni-berlin.de>
funkyville wrote:
> All I need my script to do is go to a website and download a .pdf from
> that site and save it to my hard drive. Example,
> http://www.anysite.com/report.pdf
>
> This approach won't work with PDFs.
Why not. Did you try it?
I would use wget in this situation.
gtoomey
------------------------------
Date: Tue, 9 Nov 2004 01:34:36 -0800
From: "David Filmer" <ineverreadanythingsenttome@hotmail.com>
Subject: How to save/restore a hash of hashes?
Message-Id: <Q5udneqQc_CUDQ3cRVn-hA@comcast.com>
I want to be able to save the values of a hash of hashes (of hashes of
hashes, actually) to a textfile and be able to restore the hash (at a later
time) by reading the textfile.
If it were a simple hash, it would be trivial to save/reload the key/value
pairs. But a hash of hashes (of hashes of hashes) doesn't lend itself to
such a trivial solution. I could do a "brute force" approach, drilling down
to each value and saving it in an expected order (and restore it in a
brute-force approach in the same order) but that doesn't seem very elegant
(in fact, it's downright ghastly).
I would appreciate a suggestion as to how I might accomplish this in an
elegant fashion.
Thanks!
------------------------------
Date: 9 Nov 2004 09:50:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to save/restore a hash of hashes?
Message-Id: <cmq3sh$sf3$1@mamenchi.zrz.TU-Berlin.DE>
David Filmer <ineverreadanythingsenttome@hotmail.com> wrote in comp.lang.perl.misc:
> I want to be able to save the values of a hash of hashes (of hashes of
> hashes, actually) to a textfile and be able to restore the hash (at a later
> time) by reading the textfile.
Data::Dumper or Storable (standard modules). FreezeThaw from CPAN.
Anno
------------------------------
Date: Tue, 9 Nov 2004 02:00:53 -0800
From: "David Filmer" <ineverreadanythingsenttome@hotmail.com>
Subject: Re: How to save/restore a hash of hashes?
Message-Id: <u-CdnagrF-qvCw3cRVn-2g@comcast.com>
Awesome - thanks! A quick read-thru of Data::Dumper looks great but Storable
(and prehaps FreezeThaw - still figuring that one out) is incredible and
exactly what I need. I very much appreciate you pointing me in this
direction.
Cheers!
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:cmq3sh$sf3$1@mamenchi.zrz.TU-Berlin.DE...
> Data::Dumper or Storable (standard modules). FreezeThaw from CPAN.
>
> Anno
------------------------------
Date: Mon, 08 Nov 2004 20:20:20 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: matching all perldoc names but no more
Message-Id: <10p03g7foudrle3@news.supernews.com>
Jim Gibson wrote:
> In article <10ovpuorbdjee88@news.supernews.com>, wana
> <ioneabu@yahoo.com> wrote:
>
>> Jim Gibson wrote:
>>
>> > In article <10oq6todvqrl2e8@news.supernews.com>, wana
>> > <ioneabu@yahoo.com> wrote:
>> >
>> >> Tad McClellan wrote:
>> >>
>> >> > wana <ioneabu@yahoo.com> wrote:
>> >> >
>> >
>> > [ problem of untainting perldoc subjects snipped ]
>> >
>> >> >
>> >> > I think this ought to work though: ^(\w|::)+$
>> >>
>> >> I only avoided \w because perlre states that it is not portable across
>> >> character sets and may be insecure, which is critical in my case.
>> >> That may or may not be an issue in my program.
>> >
>> > Where in perldoc perlre does it say that? It does not say it in the
>> > version (5.8.5) on my computer. I could not find the string 'insecure'
>> > anywhere in 'perldoc perlre', and 'portable' only occurs once in a
>> > discussion of character ranges.
>>
>> The words to look for are 'unsafe' and 'unportable' about 78% into
>> perlre. The discussion about character ranges is what I am talking about.
>> [a-zA-Z1-9] is safe but \w may vary in different locales.
>
> The warning is about defining your own character ranges, such as [ -~]
> for the ascii printable set. That may give an error in other character
> sets. The doc says nothing about character classes such as \w being
> unsafe or unportable across character sets. In fact, it implies that
> using \w is safer than defining your own character sets.
>
> Here it is from perlre:
>
> "Note also that the whole range idea is rather unportable between char-
> acter sets--and even within character sets they may cause results you
> probably didn't expect. A sound principle is to use only ranges that
> begin from and end at either alphabets of equal case ([a-e], [A-E]), or
> digits ([0-9]). Anything else is unsafe. If in doubt, spell out the
> character sets in full."
for example:
$comm = $ARGV[0];
if ($comm =~ /^\w+/$) # the same as ^[a-zA-Z1-9_]+$
{
`echo $comm`
}
this prevents a user from slipping in dangerous characters like | or >
etc...
Suppose a new character set comes along and is described by a different
locale. Then suppose this code is cut&paste or included otherwise within
the new locale which has a character in its alphabet that the shell
interpretes as | for example. Now there is a security compromise, hence it
is insecure and unsafe. I don't know if this is possible, but that's what
I read into the statement in perlre. If this is possible, it is clearly a
potential, though unlikely, security risk. I believe perlsec touches
briefly on the same subject.
wana
------------------------------
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 7381
***************************************