[23718] in Perl-Users-Digest
Perl-Users Digest, Issue: 5924 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 11 00:05:46 2003
Date: Wed, 10 Dec 2003 21:05:08 -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 Wed, 10 Dec 2003 Volume: 10 Number: 5924
Today's topics:
$socket->timeout usage <asu1@c-o-r-n-e-l-l.edu>
(RFD) ANNOUNCE: Time::Format v0.13 <REMOVEsdnCAPS@comcast.net>
Re: Beginners Program <matthew.garrish@sympatico.ca>
Re: CGI input variable - regular expression question (G Klinedinst)
Re: CGI input variable - regular expression question (G Klinedinst)
Re: CGI input variable - regular expression question <asu1@c-o-r-n-e-l-l.edu>
Re: CGI input variable - regular expression question <flavell@ph.gla.ac.uk>
Re: CGI input variable - regular expression question <flavell@ph.gla.ac.uk>
Re: CGI input variable - regular expression question <asu1@c-o-r-n-e-l-l.edu>
Re: Character class [\W_] clarification (Fiaz Idris)
Re: Character class [\W_] clarification (Sam Holden)
Re: Character class [\W_] clarification <uri@stemsystems.com>
Re: Idiom for array index that I'm foreach'ing over? <abigail@abigail.nl>
In search of elegant code - searching keys of hashes in (David Filmer)
Re: In search of elegant code - searching keys of hashe <REMOVEsdnCAPS@comcast.net>
Re: In search of elegant code - searching keys of hashe <no_spam_for_jkeen@verizon.net>
Re: In search of elegant code - searching keys of hashe <bigiain@mightymedia.com.au>
Re: In search of elegant code - searching keys of hashe <asu1@c-o-r-n-e-l-l.edu>
Re: In search of elegant code - searching keys of hashe <uri@stemsystems.com>
Re: Module installation and permissions <cwilbur@mithril.chromatico.net>
no $workbook->Close; in Spreadsheet::WriteExcel but in (Zhidian Du)
Re: Proposal: new module, Array::Each? <REMOVEsdnCAPS@comcast.net>
Re: script writer required (Tad McClellan)
Re: Static Content Management -- Baking Pages rather th <henq _ replace 0 by o <hvtijen@h0tmail.c0m>>
Re: What is '_' <parv_@yahooWhereElse.com>
What's more efficient, hash or array <sun_tong@users.sourceforge.net>
Re: What's more efficient, hash or array <REMOVEsdnCAPS@comcast.net>
Re: What's more efficient, hash or array <invalid-email@rochester.rr.com>
Re: What's more efficient, hash or array <no_spam_for_jkeen@verizon.net>
Re: What's more efficient, hash or array (Tad McClellan)
Re: What's more efficient, hash or array <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Dec 2003 03:03:33 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: $socket->timeout usage
Message-Id: <Xns944DE065E4647asu1cornelledu@132.236.56.8>
Consider the following script:
#!/usr/bin/perl
use strict;
use warnings;
use Socket;
use IO::Socket;
my $s = IO::Socket::INET->new(
LocalAddr => '127.0.0.1',
LocalPort => 50000,
Reuse => 1,
Listen => 5,
Timeout => 10,
);
die "$@" unless $s;
while(my $c = $s->accept()) {
$c->timeout(5);
while($c->getline()) {
print;
}
$s->shutdown(2);
}
print $@ if $@;
__END__
Now, the 10 second timeout I set on $s works like I expected: If a
connection does arrive in 10 seconds, accept fails with:
C:\develop\perl> sto.pl
accept: timeout
on both Windows XP and FreeBSD 4.8. OTOH, if I connect using
telnet 127.0.0.1 50000
before the accept call times out, the script just hangs waiting for input
and never times out.
Changing the while loop to:
my ($byte, $msg);
while(sysread($c, $byte, 1) == 1) {
last if $byte eq 'z';
$msg .= $byte;
print $msg, "\n";
}
does not make a difference either.
I do realize this is a naive query and I am probably missing something
obvious. I'd really appreciate some pointers.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 10 Dec 2003 19:50:36 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: (RFD) ANNOUNCE: Time::Format v0.13
Message-Id: <Xns944DD44EF3184sdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
[This is somewhat of a repost of an article I posted three months
ago.
I have received almost no feedback on this module, which means a)
It's perfect the way it is; b) Nobody uses it because it stinks; or
c) Nobody uses it because nobody knows about it. I am posting this
in case the latter is true. Feel free to comment. Or heck, feel
free to continue to ignore it. :-) ]
Time::Format v0.13 has been released. If no features are added or
bugs are fixed by Feb 1, 2004, it will be re-released as v1.0.
Time::Format is designed to be an easy-to-use time and date
formatting utility module. The format codes follow a simple pattern
and are meant to be easy to use and easy to remember. If I've done
my job well, you probably won't ever need to refer to the
documentation to look up a code, once you've learned the system. It
provides most of the functionality of POSIX::strftime (plus some
things POSIX::strftime does not provide), without annoying and
hard-to-remember % codes. (For example, I can never remember whether
%A is the weekday name and %B is the month name, or vice-versa).
In addition to a function-call interface, Time::Format also provides
a tied-hash interface, which makes formatting dates within strings
vastly easier. Some examples:
print "Today is $time{'yyyy/mm/dd'}\n";
print "Yesterday was $time{'yyyy/mm/dd', time-24*60*60}\n";
print "The time is $time{'hh:mm:ss'}\n";
print "Another time is $time{'H:mm am tz', $another_time}\n";
print "Timestamp: $time{'yyyymmdd.hhmmss.mmm'}\n";
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE/183FY96i4h5M0egRAp3VAKDhexZoR0R7276AIIuHl0wdpjzMEQCfWZZi
ORiEew60dNVVZf7T1Db1J/I=
=iTQy
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 10 Dec 2003 23:08:29 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Beginners Program
Message-Id: <p5SBb.4363$aF2.604466@news20.bellglobal.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:br76sj$mej$1@mamenchi.zrz.TU-Berlin.DE...
> Matt Garrish <matthew.garrish@sympatico.ca> wrote in comp.lang.perl.misc:
> >
> > "Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
> > news:slrnbtd04e.bfa.sholden@flexal.cs.usyd.edu.au...
> > >
> > > As an aside, for those who might know:
> > >
> > > Why is
> > > print "@";
> > > OK, but
> > > print "$";
> > > isn't?
> > >
> >
> > $" is a predefined variable. How would you then use it in a
double-quoted
> > string if the above were not an error?
>
> So is @" (though Perl doesn't use it), that's not the point.
>
> Perl treats interpolation of arrays differently than interpolation of
> scalars. Array interpolation was introduced rather late in the game.
> To make the transition as smooth as possible, Perl treats "@" in a string
> as a normal character whenever possible. The rather complex handling of
> "$" was already in place at the time and was, of course, not changed.
>
> So there really is no good reason for the different behavior, only
> history.
>
I stand corrected. I was under the (false) impression that Perl wouldn't try
and distinguish $" at the end of the string because it could just be that
you were trying to use $". Live and learn...
Matt
------------------------------
Date: 10 Dec 2003 15:18:35 -0800
From: g_klinedinst@hotmail.com (G Klinedinst)
Subject: Re: CGI input variable - regular expression question
Message-Id: <168f035a.0312101518.829b949@posting.google.com>
> \W already stands for a character class, no need to surround it with [ and
> ]. Also,
Thanks for the tip. I will use the way you demonstrated in the future.
> is more readily comprehensible and does the same thing as the statement
> above. No need for clutter.
Definitely. RegExps are hairy enough as it is.
Your 2nd post>if($name =~ m!^([A-Za-z1-9_\-/])+$!)
This expression works perfectly. My interpretation of this is that by
using the begin and end of the string symbols "^" and "&", and the "+"
character you are saying to match 1 or more of the listed characters
between the beginning and end of the string. And this states that
since no other characters( other than the ones we stated I mean ) are
present between the begin and end of line chars no others are allowed.
Got it, I think. :-) Looks like I need to go back and read the fine
print on regexps again. Thanks again.
------------------------------
Date: 10 Dec 2003 15:20:29 -0800
From: g_klinedinst@hotmail.com (G Klinedinst)
Subject: Re: CGI input variable - regular expression question
Message-Id: <168f035a.0312101520.186b2247@posting.google.com>
> The hyphen must be the first character to avoid it being seen as a range
> operator like the other hyphens. The regex above will match a string
> which consists of 1 or more of the characters in the []'s.
I think that is what was giving me the issues. As well as not bounding it.
> BTW, are you sure you don't want to allow zero?
Yes, I did. Typo. Thanks for the help.
------------------------------
Date: 10 Dec 2003 23:28:00 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Xns944DBBDAA3090asu1cornelledu@132.236.56.8>
g_klinedinst@hotmail.com (G Klinedinst) wrote in
news:168f035a.0312101518.829b949@posting.google.com:
>> \W already stands for a character class, no need to surround it with
>> [ and ]. Also,
>
> Thanks for the tip. I will use the way you demonstrated in the future.
>
>> is more readily comprehensible and does the same thing as the
>> statement above. No need for clutter.
>
> Definitely. RegExps are hairy enough as it is.
Please note Alan's response, however. If $name = '',
($name =~ /\w/) will be false whereas !($name =~ /\W/) will be true.
> Thanks again.
You are welcome.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 10 Dec 2003 23:18:54 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Pine.LNX.4.53.0312102313170.26502@ppepc56.ph.gla.ac.uk>
On Wed, 10 Dec 2003, A. Sinan Unur asked me:
> Are you a mathematician by any chance?
I think I'm going to take that as an obtuse compliment. ;-)
(My degree is in Physics[0], but Maths seemed to be an important part
of that too. Not that the genuine mathematicians would have been
satisfied with the sort that we did. "Far too little rigour" they
said.[1])
cheers
[0] "Physicists write FORTRAN in any language"
[1] please, let's skip the topical gag that springs inevitably to mind
at this spam-polluted juncture.
------------------------------
Date: Thu, 11 Dec 2003 00:05:52 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Pine.LNX.4.53.0312110001560.26502@ppepc56.ph.gla.ac.uk>
On Wed, 10 Dec 2003, A. Sinan Unur wrote:
> > Definitely. RegExps are hairy enough as it is.
>
> Please note Alan's response, however. If $name = '',
> ($name =~ /\w/) will be false whereas !($name =~ /\W/) will be true.
But I forgot to mention the possibility of coding !~ as the opposite
of =~ , which seems useful here.
------------------------------
Date: 11 Dec 2003 01:01:58 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: CGI input variable - regular expression question
Message-Id: <Xns944DCBC8C1053asu1cornelledu@132.236.56.8>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in
news:Pine.LNX.4.53.0312102313170.26502@ppepc56.ph.gla.ac.uk:
> On Wed, 10 Dec 2003, A. Sinan Unur asked me:
>
>> Are you a mathematician by any chance?
>
> I think I'm going to take that as an obtuse compliment. ;-)
It was indeed for catching the implicit assumption that $name is nonempty.
Thank you indeed for the correction.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 10 Dec 2003 17:37:59 -0800
From: ifiaz@hotmail.com (Fiaz Idris)
Subject: Re: Character class [\W_] clarification
Message-Id: <93c1947c.0312101737.470a960a@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<
> > I know that [\W] matches [^a-zA-Z_0-9]
> > [~`!@#$%^&*()-[]:;<,./"? ........and so on] but not the interpretation
> > give in (regex XXX) above.
>
> I'm still not sure what discrepancy you are seeing. /[^a-zA-Z_0-9]/
> and /\W/ match exactly the same things, as well as the redundant
> [^a-zA-Z_0-9_].
Maybe I didn't explain my confusion clearly. See Glenn Jackman's posting
for an example code that shows the difference.
[\W] does not replace the underscore, but
[\W_] also replaces the underscore.
Programming Perl says
Symbol ||| Meaning ||| As Bytes
\W ||| Non-(word character) ||| [^a-zA-Z0-9_]
According to the above representation for [\W] I assumed
Point 1:
[\W_] is equivalent to [^a-zA-Z0-9__] ----> (two underscores)
and thought that the last underscore is actually unnecessary.
Point 2:
But, [\W_] is actually equivalent to [^~!@#$%^&*()....._]
that is (all the characters other than [A-Za-z0-9_] and include the [_]).
Point 2 is what actually happens when using [\W_] but the documentation
leads you to believe [\W_] is equivalent to Point 1 and we all know that
that is not the case by running the sample code I mentioned before.
So, where in the docs (anywhere) that points this out.
I hope I have made myself clear.
------------------------------
Date: 11 Dec 2003 02:13:41 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Character class [\W_] clarification
Message-Id: <slrnbtfkmk.lm.sholden@flexal.cs.usyd.edu.au>
On 10 Dec 2003 17:37:59 -0800, Fiaz Idris <ifiaz@hotmail.com> wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<
>
>> > I know that [\W] matches [^a-zA-Z_0-9]
>
>> > [~`!@#$%^&*()-[]:;<,./"? ........and so on] but not the interpretation
>> > give in (regex XXX) above.
>>
>> I'm still not sure what discrepancy you are seeing. /[^a-zA-Z_0-9]/
>> and /\W/ match exactly the same things, as well as the redundant
>> [^a-zA-Z_0-9_].
>
> Maybe I didn't explain my confusion clearly. See Glenn Jackman's posting
> for an example code that shows the difference.
>
> [\W] does not replace the underscore, but
> [\W_] also replaces the underscore.
>
> Programming Perl says
>
> Symbol ||| Meaning ||| As Bytes
> \W ||| Non-(word character) ||| [^a-zA-Z0-9_]
>
> According to the above representation for [\W] I assumed
>
> Point 1:
> [\W_] is equivalent to [^a-zA-Z0-9__] ----> (two underscores)
> and thought that the last underscore is actually unnecessary.
That's a pretty silly assumption. \W matches the same things as
matched by [^a-zA-Z_0-9] (ignoring locales for the moment).
[AB] matches A or B. so [\W_] matches \W or _. "_" isn't matched
by \W but is by _, hence it matches [\W_].
If I squinted I might be able to see how you could think [\W_] might
be the same as [[^a-zA-Z_0-9]_] (by treating the explanation of
what it matches as a literal expansion). But why anyone would think
extra characters would be magically placed inside the []s is beyong
me...
> Point 2:
> But, [\W_] is actually equivalent to [^~!@#$%^&*()....._]
> that is (all the characters other than [A-Za-z0-9_] and include the [_]).
>
> Point 2 is what actually happens when using [\W_] but the documentation
> leads you to believe [\W_] is equivalent to Point 1 and we all know that
> that is not the case by running the sample code I mentioned before.
>
> So, where in the docs (anywhere) that points this out.
perldoc perlre:
\W Match a non-"word" character
and
You may use "\w", "\W", "\s", "\S", "\d", and "\D" within character
classes
I can't see how you could possibly come to your "Point 1" interpretation.
--
Sam Holden
------------------------------
Date: Thu, 11 Dec 2003 04:25:43 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Character class [\W_] clarification
Message-Id: <x765go7zg8.fsf@mail.sysarch.com>
>>>>> "FI" == Fiaz Idris <ifiaz@hotmail.com> writes:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<
>> > I know that [\W] matches [^a-zA-Z_0-9]
>> > [~`!@#$%^&*()-[]:;<,./"? ........and so on] but not the interpretation
>> > give in (regex XXX) above.
>>
>> I'm still not sure what discrepancy you are seeing. /[^a-zA-Z_0-9]/
>> and /\W/ match exactly the same things, as well as the redundant
>> [^a-zA-Z_0-9_].
> Maybe I didn't explain my confusion clearly. See Glenn Jackman's posting
> for an example code that shows the difference.
> [\W] does not replace the underscore, but
> [\W_] also replaces the underscore.
> Programming Perl says
> Symbol ||| Meaning ||| As Bytes
> \W ||| Non-(word character) ||| [^a-zA-Z0-9_]
> According to the above representation for [\W] I assumed
> Point 1:
> [\W_] is equivalent to [^a-zA-Z0-9__] ----> (two underscores)
> and thought that the last underscore is actually unnecessary.
you have to INVERT the class for \w to get \W. so \W does NOT contain
_. your assumption that is has 2 _ is wrong. \W has NO _ so you must add
one if you want to match it.
the key is to remember that \w is a char class and \W is all the other
chars. it is not the same as [^\w] which is sort of what you think it
is.
> Point 2:
> But, [\W_] is actually equivalent to [^~!@#$%^&*()....._]
> that is (all the characters other than [A-Za-z0-9_] and include the [_]).
> Point 2 is what actually happens when using [\W_] but the documentation
> leads you to believe [\W_] is equivalent to Point 1 and we all know that
> that is not the case by running the sample code I mentioned before.
the docs are accurate. you misinterpreted them as point 1.
> So, where in the docs (anywhere) that points this out.
what you quoted from the docs points this out.
> I hope I have made myself clear.
yes you did. and you were wrong and the docs are correct.
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 Dec 2003 00:41:07 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <slrnbtff93.les.abigail@alexandra.abigail.nl>
Michele Dondi (bik.mido@tiscalinet.it) wrote on MMMDCCLIII September
MCMXCIII in <URL:news:nj9stvor4l728tbtcd1gcuur8n9de2a4bc@4ax.com>:
][ On 09 Dec 2003 21:52:10 GMT, Abigail <abigail@abigail.nl> wrote:
][
][ >{} >Unlike Perl6, which just throws out 50 years of programming language
][ >{} >design out of the window, passes Python on the wrong side and makes
][ >{} >whitespace significant in new painful and revolting ways.
][ >{}
][ >{} Just out of curiosity: is this definitive or are there chances that
][ >{} such "features" may be removed/changed before before Perl6 is actually
][ >{} released in productive form?
][ >
][ >Nothing is definitive, but Larry and Damian seem to be convinced that
][ >the gain of saving 2 characters on an if() are worth sacrificing the
][ >non-significance of whitespace, that I say the chances are small.
][
][ It would be nice if this behaviour could be triggered somehow, say by
][ means of yet another cmd line switch or a pragma...
][
][ But shouldn't Perl6 be the "community rewrite" (IIRC) of Perl? What
][ does the community think here?!?
There are several perl6 mailinglists. Go join them if you want to know.
][ BTW: what would be the best resource for discussing own
][ ideas/questions about feaures of (any future major release of Perl,
][ but then most definitely) Perl6? Please not that I'm talking about
][ (possibly) naive or generic issues, so too technical a
][ forum/board/whatever may not be well suited for them...
Fire up your time machine and go back 3.5 years in time. Submit your RFC.
Or join the mailinglists. (I joined the first perl6 mailinglist the
very first day. I gave up on perl6 the next day).
Abigail
--
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT
------------------------------
Date: 10 Dec 2003 18:45:25 -0800
From: IneverReadAnythingSentToMe@hotmail.com (David Filmer)
Subject: In search of elegant code - searching keys of hashes in array
Message-Id: <e4c916dd.0312101845.4a50a99a@posting.google.com>
Suppose I have an array of hashes of names and social-security
numbers:
@ARRAY = (
{ first => 'John', last => 'Doe', ssn => '123-45-6789' },
{ first => 'Fred', last => 'Ree', ssn => '9876-54-321' }
);
Now suppose I want to print an error if any particular SSNs (say
'234-56-7890' and '0987-65-4321') are not found in my @ARRAY.
Obviously I can't just grep the array. I could build an intermediate
hash (%SSN) like this:
for (@ARRAY) { $SSN{$$_{'ssn'}}++ }
for (qw/234-56-7890 0987-65-4321/) {
print "Not found: $_\n" unless $SSN{$_}
}
but that's REALLY ugly (I don't like the creation of the intermediate
%SSN hash). I would appreciate suggestions for a more elegant
approach.
------------------------------
Date: Wed, 10 Dec 2003 20:57:55 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: In search of elegant code - searching keys of hashes in array
Message-Id: <Xns944DDFB7F6D9Asdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
IneverReadAnythingSentToMe@hotmail.com (David Filmer) wrote in
news:e4c916dd.0312101845.4a50a99a@posting.google.com:
> Suppose I have an array of hashes of names and social-security
> numbers:
>
> @ARRAY = (
> { first => 'John', last => 'Doe', ssn => '123-45-6789' },
> { first => 'Fred', last => 'Ree', ssn => '9876-54-321' }
> );
>
> Now suppose I want to print an error if any particular SSNs (say
> '234-56-7890' and '0987-65-4321') are not found in my @ARRAY.
> Obviously I can't just grep the array. I could build an
intermediate
> hash (%SSN) like this:
>
> for (@ARRAY) { $SSN{$$_{'ssn'}}++ }
> for (qw/234-56-7890 0987-65-4321/) {
> print "Not found: $_\n" unless $SSN{$_}
> }
>
> but that's REALLY ugly (I don't like the creation of the
intermediate
> %SSN hash). I would appreciate suggestions for a more elegant
> approach.
I can't think of a better way. I think it's uglier to loop over the
@ARRAY each time you want to check a SSN.
Perhaps you can skip the (ugly?) creation of the intermediate hash by
representing your data differently? Or at least, maintaining the
%SSN hash alongside your @ARRAY data?
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE/192QY96i4h5M0egRAot5AJ9RFzaafodA6bTCfdpkDZhb+GsP1gCg+gXY
4nWr8yxFkPsHeTXaO9DGP44=
=ZrTm
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 11 Dec 2003 03:20:21 GMT
From: "Jim Keenan" <no_spam_for_jkeen@verizon.net>
Subject: Re: In search of elegant code - searching keys of hashes in array
Message-Id: <VnRBb.48$gY4.25@nwrdny01.gnilink.net>
"David Filmer" <IneverReadAnythingSentToMe@hotmail.com> wrote in message
news:e4c916dd.0312101845.4a50a99a@posting.google.com...
> Suppose I have an array of hashes of names and social-security
> numbers:
>
> @ARRAY = (
> { first => 'John', last => 'Doe', ssn => '123-45-6789' },
> { first => 'Fred', last => 'Ree', ssn => '9876-54-321' }
> );
>
> Now suppose I want to print an error if any particular SSNs (say
> '234-56-7890' and '0987-65-4321') are not found in my @ARRAY.
> Obviously I can't just grep the array. I could build an intermediate
> hash (%SSN) like this:
>
> for (@ARRAY) { $SSN{$$_{'ssn'}}++ }
> for (qw/234-56-7890 0987-65-4321/) {
> print "Not found: $_\n" unless $SSN{$_}
> }
>
> but that's REALLY ugly (I don't like the creation of the intermediate
> %SSN hash). I would appreciate suggestions for a more elegant
> approach.
Can you store your data in the form of a hash keyed by the SSN? After all,
setting aside fraud, the SSN uniquely identifies each individual and is made
to order as a hash key:
%SSN = (
123-45-6789 => ['John', 'Doe'],
9876-54-321 => ['Fred', 'Ree'],
);
Note that while the keys in your inner hash ('first', 'last', etc.) make it
easier to read, they don't add any semantic value and their repetition
increases the possibility of typing and coding errors.
jimk
------------------------------
Date: Thu, 11 Dec 2003 14:25:06 +1100
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: In search of elegant code - searching keys of hashes in array
Message-Id: <bigiain-7F9946.14250611122003@news.fu-berlin.de>
In article <VnRBb.48$gY4.25@nwrdny01.gnilink.net>,
"Jim Keenan" <no_spam_for_jkeen@verizon.net> wrote:
> Can you store your data in the form of a hash keyed by the SSN?
So long as you keep in mind what a US-centric solution that is...
Iain (I have no SSN, but I _may_ want to buy something from your website)
--
'When I first met Katho, she had a meat cleaver in one hand and
half a sheep in the other. "Come in", she says, "Hammo's not here.
I hope you like meat.' Sharkey in aus.moto
------------------------------
Date: 11 Dec 2003 03:42:09 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: In search of elegant code - searching keys of hashes in array
Message-Id: <Xns944DE6F13D032asu1cornelledu@132.236.56.8>
Iain Chalmers <bigiain@mightymedia.com.au> wrote in news:bigiain-
7F9946.14250611122003@news.fu-berlin.de:
> In article <VnRBb.48$gY4.25@nwrdny01.gnilink.net>,
> "Jim Keenan" <no_spam_for_jkeen@verizon.net> wrote:
>
>> Can you store your data in the form of a hash keyed by the SSN?
>
> So long as you keep in mind what a US-centric solution that is...
>
> Iain (I have no SSN, but I _may_ want to buy something from your website)
Well, I seriously doubt that this involves an ecommerce site. Entering your
SSN is hardly a prerequisite for making online purchases in the U.S.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Thu, 11 Dec 2003 04:40:17 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: In search of elegant code - searching keys of hashes in array
Message-Id: <x71xrc7yry.fsf@mail.sysarch.com>
>>>>> "DF" == David Filmer <IneverReadAnythingSentToMe@hotmail.com> writes:
> Suppose I have an array of hashes of names and social-security
> numbers:
> @ARRAY = (
> { first => 'John', last => 'Doe', ssn => '123-45-6789' },
> { first => 'Fred', last => 'Ree', ssn => '9876-54-321' }
> );
> Now suppose I want to print an error if any particular SSNs (say
> '234-56-7890' and '0987-65-4321') are not found in my @ARRAY.
> Obviously I can't just grep the array. I could build an intermediate
> hash (%SSN) like this:
how is that obvious? you must have the classic newbie misconception that
grep only takes regexes which is wrong. grep can take any expression to
test. so you can grep your array easily:
foreach my $ssn ( qw( some ssn values) ) {
@found = grep $_->{ssn} eq $ssn, @array ;
do something based on @found
}
> for (@ARRAY) { $SSN{$$_{'ssn'}}++ }
> for (qw/234-56-7890 0987-65-4321/) {
> print "Not found: $_\n" unless $SSN{$_}
> }
> but that's REALLY ugly (I don't like the creation of the intermediate
> %SSN hash). I would appreciate suggestions for a more elegant
> approach.
as someone else said, indexing by ssn is another solution and one i
would recommend. if you do this search often, then building the other
hash is worth it and can be done even simpler than your example:
my %is_ssn ;
@is_ssn{ map $_->{ssn}, @ARRAY } = () ;
# test with exists
or
my %is_ssn = map { $_->{ssn}, 1} @ARRAY ;
but those only tell you if an ssn exists. if you want to find the record
by ssn just replace the 1 with $_ in the second and call the hash
ssn_to_rec or something similar.
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: Thu, 11 Dec 2003 02:45:11 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Module installation and permissions
Message-Id: <87he08ulv3.fsf@mithril.chromatico.net>
>>>>> "AJ" == Alexandre Jaquet <alexj@freesurf.ch> writes:
AJ> Hi, I need to install new module on my shell but I didn't have
AJ> a root account.
perldoc -q 'my own module'
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: 10 Dec 2003 20:53:18 -0800
From: zdu@cs.nmsu.edu (Zhidian Du)
Subject: no $workbook->Close; in Spreadsheet::WriteExcel but in Win32::OLE?
Message-Id: <e4c69a32.0312102053.6ee97a5d@posting.google.com>
When I write a program that need the xls file immediately after
finishing writing the xls file. Why there is no $workbook->Close; to
close the current file? If I use this single program, it's ok. But
how can I let the .xls file to be used by the following programs?
I found in Win32::OLE, it has the counterpart.
Thanks.
Z. Du
#! /usr/bin/perl
use Spreadsheet::WriteExcel;
use Spreadsheet::WriteExcel::Big;
my $workbook = Spreadsheet::WriteExcel->new( "myfirstExcel.xls" );
my $worksheet = $workbook->addworksheet();
my $workformat = $workbook->addformat();
$workformat->set_bold(1);
$row = 0;
$coloumn = 0;
$workformat->set_bold( 1 );
#$workformat->set_column('A:A', 125);
#worksheet->Columns("A:A")->{ColumnWidth} = 25;
$worksheet->set_column( 'A:A', 125);
$worksheet->set_column( 'B:D', 125);
#$worksheet->write( 0, 0, "Results", $workformat );
$worksheet->write( 0, 0, "Results");
$worksheet->write( 0, 1, "Long resutl is how to seccuess" );
$workformat->set_bold();
$workformat->set_bottom(6);
$worksheet->set_column(0, 0, 12 );
$worksheet->set_column(11, 11, 12);
my $dir = "/u/dian/test";
#$workbook->SaveAs( $dir . '/perl_ole.xls');
#--------------Here it is-----------
#$workbook->Close;
print "test\n";
------------------------------
Date: Wed, 10 Dec 2003 20:01:49 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Proposal: new module, Array::Each?
Message-Id: <Xns944DD6359D37Dsdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Brad Baxter <bmb@ginger.libs.uga.edu> wrote in
news:Pine.A41.4.58.0312091240460.6362@ginger.libs.uga.edu:
> [This stems somewhat from discussions in the thread:
> Idiom for array index that I'm foreach'ing over?]
>
> I'm considering making a new module with the tentative name
> Array::Each.
>
> A draft is available here:
>
> http://www.vitabrevis.ws/perl/modules/Array/Each.pm
> http://www.vitabrevis.ws/perl/modules/Array/Each.pod.html
>
> It's incomplete, but I want to discuss the idea before proceeding
> further.
>
> 1. Is Array::Each acceptable? Perhaps Array::Parallel, or
> Array::Iteration?
>
> 2. Are the subroutine names acceptable? In particular, I expect
> negative reactions to each(), since it would clobber each( %hash ),
so
> alternative suggestions are welcome.
>
> 3. Is this a good approach? Are all those options needed? Does
it
> matter that it doesn't return lvalues like foreach ( @array )?
>
> 4. Should someone else do this/Has someone else done this? I did
> study the CPAN module list and didn't find a close match. That I
> missed one would not surprise me.
>
> 5. I imagine sometime adding an OO interface along these lines:
>
> my $set = Array::Each->new( @x, @y );
> my( $i, $x, $y ) = $set->each();
>
> Among other things, this should allow iterating over the same set
of
> arrays using different iterators. Should I bother?
I think an OO interface is a good idea. If you do that, don't return
the iteration value with the array values. Use a separate method for
that.
Perhaps something like this:
$set = Array::Each->new (@x, @y);
while (my ($x, $y) = $set->each())
{
print "Iteration number ", $set->index(), "\n";
print " x = $x; y = $y\n";
print " last iteration!\n" if $set->exhausted();
}
$set->rewind();
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE/19BsY96i4h5M0egRAmQeAKDXldiTn7DoAUwg99VLtKZDdEvfMgCgie64
TKeuP9sACsC0O/+Z2PhhAz8=
=z5kt
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 10 Dec 2003 17:12:06 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: script writer required
Message-Id: <slrnbtfa26.v0u.tadmc@magna.augustmail.com>
Richard <webmaster@missingfriends.net> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnbteuih.ute.tadmc@magna.augustmail.com...
>> Richard <webmaster@missingfriends.net> wrote:
>>
>> > I am looking for a script-writer
>>
>>
>> Then post to a newsgroup with "jobs" in its name.
> Glad you are earning enough to turn down an offer
Thank you for your concern.
If I _was_ looking for a job, I wouldn't want one with
someone who abuses Usenet, so we couldn't hook up anyway.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 11 Dec 2003 01:18:56 +0100
From: "henq" <henq _ replace 0 by o <hvtijen@h0tmail.c0m>>
Subject: Re: Static Content Management -- Baking Pages rather than Frying them
Message-Id: <3fd7b7ee$0$168$1b62eedf@news.wanadoo.nl>
Take a look at the ttree program, part of the wonderful
www.template-toolkit.org package.
Of the template tags, take especially note of [% WRAPPER %], as it allows
you to make your whole site to have a shared border.
henq
"Ben B" <google@dotinf.co.uk> wrote in
news:7881e289.0312100954.e8d347a@posting.google.com...
> All
>
> I'm looking for a tool or series of tools to help me manage the
> content of a website. My request is odd because I have no need to
> manage content on-the-fly. I would be happy to regenerate pages each
> time the content is updated.
>
> I'd need to be able to --
> + supply a 'template' HTML file
> + a file (or optionally a database) to pad out the template
> + include dynamically created navigation -- breadcrumbs and main menu
> for each page
>
> I'd be happy to work in Perl or PHP, but must be able to use these
> tools on a Windows platform. My preference would be for Open Source
> software.
>
> Can you let me know what the 'state of the art' is in this niche area?
> I have looked at some Perl scripts, but they seem not to work on
> Windows (and this is backed up by other user's comments).
>
> Thanks
>
> Ben
------------------------------
Date: Thu, 11 Dec 2003 04:19:02 GMT
From: parv <parv_@yahooWhereElse.com>
Subject: Re: What is '_'
Message-Id: <slrnbtfs9p.19m.parv_@localhost.holy.cow>
in message <x7r7zdgtcr.fsf@mail.sysarch.com>,
wrote Uri Guttman ...
>>>>>> "p" == parv <parv_@yahooWhereElse.com> writes:
>
> p> sub routine
> p> {
> p> my $file = shift;
>
> p> if ( -e $file )
> p> {
> p> # do something
> p> return;
> p> }
>
> p> if ( -d $file )
>
> you can use _ there.
Splendid. I suspected that i could, but was not really sure until
now.
> p> if ( function() )
> p> {
> p> # do something else
> p> return;
> p> }
> p> }
>
> p> sub function { return -f _; }
>
> if nothing has done a stat or -X since the previous one on $file, then
> you are ok. but i wouldn't trust your code to not do that. _ is
> basically an operator but it acts like a global variable with no
> scoping. i would never use it outside the immediate area which had
> the original stat call.
On one hand, i would have used _ as described in function() now that
i am sure about its scope/lifetime/update (and that its an operator
that behaves like a variable). On the other, one cannot never be
too sure when file tests are happening often. In short, i agree w/
you Uri.
- parv
--
In order to reach me, do away w/ WhereElse in the address.
------------------------------
Date: Thu, 11 Dec 2003 02:22:45 GMT
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: What's more efficient, hash or array
Message-Id: <f1fe1c3a0116d67cb96e24b0d1c412f4@news.teranews.com>
Hi,
Consider the following data structure, what's more efficient, hash or array?
$precord{name},
$precord{age},
$precord{birthday},
I used to used this form. It is clearer. Then one day I thought
that using hash should be expensive than using the direct-access
array. So I change the above hash into array:
$precord[$NDX_NAME],
$precord[$NDX_AGE],
$precord[$NDX_BIRTHDAY],
But just recently I read somewhere that hash is more efficient
that array.
So, I am really curious to know what's more efficient in the above
two approaches, and how much better one over the other. Thanks.
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Wed, 10 Dec 2003 21:01:18 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: What's more efficient, hash or array
Message-Id: <Xns944DE04A836D4sdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
* Tong * <sun_tong@users.sourceforge.net> wrote in
news:f1fe1c3a0116d67cb96e24b0d1c412f4@news.teranews.com:
> Consider the following data structure, what's more efficient, hash
or
> array?
>
> $precord{name},
> $precord{age},
> $precord{birthday},
>
> I used to used this form. It is clearer. Then one day I thought
> that using hash should be expensive than using the direct-access
> array. So I change the above hash into array:
>
> $precord[$NDX_NAME],
> $precord[$NDX_AGE],
> $precord[$NDX_BIRTHDAY],
>
> But just recently I read somewhere that hash is more efficient
> that array.
I'm curious where you read that.
> So, I am really curious to know what's more efficient in the above
> two approaches, and how much better one over the other. Thanks.
I don't think it matters a whole heck of a lot. You can gain a small
measure of speed by using constants for the indices instead of
variables that you set. But frankly, if speed is so important that
you're considering jumping through hoops in order to shave a little
time off, you're using the wrong language.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE/195aY96i4h5M0egRAtPjAJ9K4nMoeG9uF2AUr8OHK3SKY7CTXACdEz5Q
DcO/gNaIg2Us9ZkbpejMtvw=
=xf3t
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 11 Dec 2003 03:06:53 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: What's more efficient, hash or array
Message-Id: <3FD7DABC.1050909@rochester.rr.com>
* Tong * wrote:
> Hi,
>
> Consider the following data structure, what's more efficient, hash or array?
>
> $precord{name},
> $precord{age},
> $precord{birthday},
>
> I used to used this form. It is clearer. Then one day I thought
> that using hash should be expensive than using the direct-access
> array. So I change the above hash into array:
>
> $precord[$NDX_NAME],
> $precord[$NDX_AGE],
> $precord[$NDX_BIRTHDAY],
>
> But just recently I read somewhere that hash is more efficient
> that array.
>
> So, I am really curious to know what's more efficient in the above
> two approaches, and how much better one over the other. Thanks.
Why don't you
use Benchmark;
and find out?
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Thu, 11 Dec 2003 03:09:48 GMT
From: "Jim Keenan" <no_spam_for_jkeen@verizon.net>
Subject: Re: What's more efficient, hash or array
Message-Id: <0eRBb.308$CO2.70@nwrdny02.gnilink.net>
"* Tong *" <sun_tong@users.sourceforge.net> wrote in message
news:f1fe1c3a0116d67cb96e24b0d1c412f4@news.teranews.com...
> Hi,
>
> Consider the following data structure, what's more efficient, hash or
array?
>
> $precord{name},
> $precord{age},
> $precord{birthday},
>
> I used to used this form. It is clearer. Then one day I thought
> that using hash should be expensive than using the direct-access
> array. So I change the above hash into array:
>
> $precord[$NDX_NAME],
> $precord[$NDX_AGE],
> $precord[$NDX_BIRTHDAY],
>
> But just recently I read somewhere that hash is more efficient
> that array.
>
> So, I am really curious to know what's more efficient in the above
> two approaches, and how much better one over the other. Thanks.
>
Supply a definition of "efficient." The one I use, at its most general, is
"useful output divided by input" -- but that still requies that I define
"useful." So your measure of efficiency depends entirely on your definition
of utility.
------------------------------
Date: Wed, 10 Dec 2003 21:23:02 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What's more efficient, hash or array
Message-Id: <slrnbtfoom.val.tadmc@magna.augustmail.com>
* Tong * <sun_tong@users.sourceforge.net> wrote:
> Consider the following data structure, what's more efficient, hash or array?
use Benchmark;
with your actual data, and you can see for yourself.
> $precord{name},
> $precord{age},
> $precord{birthday},
>
> I used to used this form. It is clearer. Then one day I thought
> that using hash should be expensive than using the direct-access
^^^^^
> array. So I change the above hash into array:
It depends on what "use" your "using" is.
> $precord[$NDX_NAME],
> $precord[$NDX_AGE],
> $precord[$NDX_BIRTHDAY],
>
> But just recently I read somewhere that hash is more efficient
> that array.
Efficient at what, exactly?
Memory usage?
Access time?
Time to look something up? (hashes kick butt here)
Time to add an entry?
Time to remove an entry?
Programming time, both development and maintenance (this costs the
most, so it is the most-often optimized one).
> So, I am really curious to know what's more efficient in the above
> two approaches, and how much better one over the other. Thanks.
It depends on what you are going to do with them.
What are you going to do with them?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 11 Dec 2003 03:44:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: What's more efficient, hash or array
Message-Id: <eKRBb.4125$GE.55@nwrddc01.gnilink.net>
* Tong * wrote:
> Consider the following data structure, what's more efficient, hash or
> array?
>
> $precord{name},
> $precord{age},
> $precord{birthday},
>
> I used to used this form. It is clearer. Then one day I thought
> that using hash should be expensive than using the direct-access
> array. So I change the above hash into array:
>
> $precord[$NDX_NAME],
> $precord[$NDX_AGE],
> $precord[$NDX_BIRTHDAY],
>
> But just recently I read somewhere that hash is more efficient
> that array.
A program using the hash is much more efficient to program and much more
efficient to maintain.
An array whose values types are all over the place (what does a name have in
common with an age?) is just a nightmare to understand and to use.
Just imagine: would it make sense to sort that array? Would it make sense to
compute the average? Would any of the typical array operations make sense?
If not, then probably an array is not the right data structure.
Oh, you didn't mean efficiency in programming and maintance but efficiency
at runtime? Well, for maybe 99.9% of all applications runtime efficiency is
really no issue. Those programs are waiting for I/O, for human interaction,
are run as batch processes, or, or, or, ....
Ease of programming and in particular maintenance is far more important and
valuable.
If indeed you are in a situation where you are doing something very
time-consuming like maybe DNA analysis or fluid dynamics or astronomical
simulations then the first step is always to optimize your algorithm. That
is where you can make a real difference.
And then if that is not sufficient, switch to a different programming
language, e.g. C or even assembler for the most time-critical parts.
But performance gains from using an array over a hash or vice versa are
really neglegable and often not even noticable.
jue
------------------------------
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.
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 5924
***************************************