[16153] in Perl-Users-Digest
Perl-Users Digest, Issue: 3565 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 16:32:58 2000
Date: Mon, 10 Jul 2000 13:32:45 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963261165-v9-i3565@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 10 Jul 2000 Volume: 9 Number: 3565
Today's topics:
Going through loops the other way <robertNOroSPAM@kronos.custard.org.invalid>
Re: Going through loops the other way <pap@sotonians.org.uk>
Re: Going through loops the other way (Rafael Garcia-Suarez)
Re: Going through loops the other way <kjetilskotheim@iname.com>
Re: Going through loops the other way <foo@bar.va>
Re: Going through loops the other way (Abigail)
Re: Going through loops the other way <pap@sotonians.org.uk>
Re: Going through loops the other way <pap@sotonians.org.uk>
Re: Going through loops the other way (Abigail)
Re: Going through loops the other way <R.W.Phillips@cs.cf.ac.uk>
Re: Going through loops the other way (Tad McClellan)
Re: Golf problem <cboyd@holyrood.ed.ac.uk>
GPM, ncurses, and other console joy riemann@home.com
graphics inserted into pdf jponder9@my-deja.com
Re: graphics inserted into pdf <randy@theoryx5.uwinnipeg.ca>
Has SNMP replaced Net:SNMP ? <john@hennessy.net.au>
Hash keys question <ed@nospam.com>
Re: Hash keys question <makarand_kulkarni@My-Deja.com>
Re: Hash keys question (Tad McClellan)
Re: Hash keys question (Keith Calvert Ivey)
Re: Hash keys question (Tad McClellan)
Re: Hash keys question (Abigail)
Hash vs. Array memory usage <webmaster@archiTacTic.com>
Have you seen this apache error? boris_kitsis@my-deja.com
Help - FTP scripting with Perl on Win32 ramagoon@yahoo.com
Re: Help - FTP scripting with Perl on Win32 (Eric Bohlman)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 05 Jul 2000 08:48:39 -0700
From: Robert <robertNOroSPAM@kronos.custard.org.invalid>
Subject: Going through loops the other way
Message-Id: <1924e5da.ee99dbda@usw-ex0103-019.remarq.com>
Hello,
I am writing a Perl script that will look through the contents of
a data file line by line. I have setup a "For" loop which reads
from start to finish as follows:
for ($a = 0; $a < @usernames; $a++) {
do stuff
}
Now I want to change this so that the array is looped from
"finish to start", i.e. the other direction. I thought it would
be a simple matter of doing the following:
for ($a < @usernames; $a = 0; $a--) {
do stuff
}
But it doesn't work. Is there a function that will read how long
the array is so that it can start from the last value and work
downwards?
Thanks for any help you can offer.
Rob.
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Wed, 05 Jul 2000 16:58:39 +0000
From: "Paul Taylor" <pap@sotonians.org.uk>
Subject: Re: Going through loops the other way
Message-Id: <xZI85.13056$X75.417483@nnrp4.clara.net>
In article <1924e5da.ee99dbda@usw-ex0103-019.remarq.com>, Robert
<robertNOroSPAM@kronos.custard.org.invalid> wrote:
> Now I want to change this so that the array is looped from
> "finish to start", i.e. the other direction. I thought it would
> be a simple matter of doing the following:
>
> for ($a < @usernames; $a = 0; $a--) {
> do stuff
> }
>
> But it doesn't work. Is there a function that will read how long the
> array is so that it can start from the last value and work downwards?
You can use the $# prefix on a list identifier to get the index
of the last element.
This should work...
my @usernames = ( 'ben', 'bill', 'bob' ) ;
for ( $a = $#usernames ; $a >= 0 ; $a-- ) {
print $usernames[$a] . "\n" ;
}
Regards,
Pap.
------------------------------
Date: Wed, 05 Jul 2000 16:08:42 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Going through loops the other way
Message-Id: <slrn8m6nkn.4ih.rgarciasuarez@rafael.kazibao.net>
Robert wrote in comp.lang.perl.misc:
>Hello,
>
>I am writing a Perl script that will look through the contents of
>a data file line by line. I have setup a "For" loop which reads
>from start to finish as follows:
>
>for ($a = 0; $a < @usernames; $a++) {
> do stuff
> }
This is a C-like for loop. You can use a more perlish form:
foreach my $username (@usernames) {
# do stuff..
}
(see the perlsyn manpage, section on foreach loops).
>Now I want to change this so that the array is looped from
>"finish to start", i.e. the other direction. I thought it would
>be a simple matter of doing the following:
>
>for ($a < @usernames; $a = 0; $a--) {
> do stuff
> }
This is not even a C-like loop.
>But it doesn't work. Is there a function that will read how long
>the array is so that it can start from the last value and work
>downwards?
C-like syntax:
for ($a = $#usernames ; $a >= 0 ; $a--) {...}
Convenient perl syntax:
foreach my $username (reverse @usernames) {
# do stuff...
}
--
Rafael Garcia-Suarez
------------------------------
Date: Wed, 05 Jul 2000 17:13:07 +0200
From: Kjetil Skotheim <kjetilskotheim@iname.com>
To: Robert <robertNOroSPAM@kronos.custard.org.invalid>
Subject: Re: Going through loops the other way
Message-Id: <39635E93.5C83272F@iname.com>
Robert wrote:
>
> Hello,
>
> I am writing a Perl script that will look through the contents of
> a data file line by line. I have setup a "For" loop which reads
> from start to finish as follows:
>
> for ($a = 0; $a < @usernames; $a++) {
> do stuff
> }
>
> Now I want to change this so that the array is looped from
> "finish to start", i.e. the other direction. I thought it would
> be a simple matter of doing the following:
>
> for ($a < @usernames; $a = 0; $a--) {
> do stuff
> }
Hmm, try: for($a=@usernames-1; $a == 0; $a--)
But in most cases something like this is better:
for $username (reverse @usernames){
do stuff with $username
}
Or the same: for(reverse@usernames){ do stuff with $_ }
Or maybe:
while($username=pop(@usernames)){
$username.........
}
...in my opinion the "for(...;...;...)"-construct, which is ok
in C/C++, should most often be replaced by "for(list)" in Perl.
> Thanks for any help you can offer.
>
> Rob.
>
--
Kjetil Skotheim
kjetilskotheim@iname.com
------------------------------
Date: Wed, 05 Jul 2000 18:15:33 +0200
From: Marco Natoni <foo@bar.va>
Subject: Re: Going through loops the other way
Message-Id: <39635F25.8E46DA73@bar.va>
Robert,
Robert wrote:
> I am writing a Perl script that will look through the contents
> of a data file line by line. I have setup a "For" loop which
> reads from start to finish as follows:
> for ($a = 0; $a < @usernames; $a++) {
> do stuff
> }
It sounds like
foreach (@usernames) { do_something $_ }
> Now I want to change this so that the array is looped from "finish
> to start", i.e. the other direction. I thought it would be a
> simple matter of doing the following:
> for ($a < @usernames; $a = 0; $a--) {
> do stuff
> }
Very like (but not entirely) to
foreach (reverse @usernames) { do_something $_ }
Best regards,
Marco
------------------------------
Date: 05 Jul 2000 12:36:54 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Going through loops the other way
Message-Id: <slrn8m6q2r.ibb.abigail@alexandra.delanet.com>
Robert (robertNOroSPAM@kronos.custard.org.invalid) wrote on MMD September
MCMXCIII in <URL:news:1924e5da.ee99dbda@usw-ex0103-019.remarq.com>:
<> Hello,
<>
<> I am writing a Perl script that will look through the contents of
<> a data file line by line. I have setup a "For" loop which reads
<> from start to finish as follows:
<>
<> for ($a = 0; $a < @usernames; $a++) {
<> do stuff
<> }
<>
<> Now I want to change this so that the array is looped from
<> "finish to start", i.e. the other direction. I thought it would
<> be a simple matter of doing the following:
Really? What makes you thing that? Did you bother to look up the
syntax of for()? Then it would be been clear instantly why your
approach is going to fail.
<> for ($a < @usernames; $a = 0; $a--) {
<> do stuff
<> }
<>
<> But it doesn't work. Is there a function that will read how long
<> the array is so that it can start from the last value and work
<> downwards?
Yes, there is such a "function" and YOU HAVE BEEN USING IT IN BOTH
CODE FRAGMENTS!
Please, try to understand your own code.
Take your first code fragment. Study it. Learn how it works. If you've
figured that out, the solution to your problem will be obvious.
(But I'm sure someone will spoonfeed you a canned solution).
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
------------------------------
Date: Wed, 05 Jul 2000 17:37:48 +0000
From: "Paul Taylor" <pap@sotonians.org.uk>
Subject: Re: Going through loops the other way
Message-Id: <eyJ85.13066$X75.418448@nnrp4.clara.net>
> But in most cases something like this is better:
>
> for $username (reverse @usernames){
> do stuff with $username
> }
>
Damn this C-like brain!
Good points for Perl programmers without
baggage from n other languages ( and even
for those who do! ).
Pap.
------------------------------
Date: Wed, 05 Jul 2000 17:40:27 +0000
From: "Paul Taylor" <pap@sotonians.org.uk>
Subject: Re: Going through loops the other way
Message-Id: <KAJ85.13068$X75.418425@nnrp4.clara.net>
> (But I'm sure someone will spoonfeed you a canned solution).
>
Or two or three, as it turned out....
P.
------------------------------
Date: 05 Jul 2000 15:53:33 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Going through loops the other way
Message-Id: <slrn8m75jh.ibb.abigail@alexandra.delanet.com>
Paul Taylor (pap@sotonians.org.uk) wrote on MMD September MCMXCIII in
<URL:news:eyJ85.13066$X75.418448@nnrp4.clara.net>:
## > But in most cases something like this is better:
## >
## > for $username (reverse @usernames){
## > do stuff with $username
## > }
## >
##
## Damn this C-like brain!
##
## Good points for Perl programmers without
## baggage from n other languages ( and even
## for those who do! ).
One has to realize that using reverse has two drawbacks:
- It's less efficient, cause it has to build a list, where the simple
case of for (@user) can be optimized.
- You work with a *copy* of the elements, so if you need to modify the
elements, you're out of luck. Both for (@array) and for ($index = 0;
$index < @array; $index ++) {} give you references to the element,
either implicit or explicit.
Abigail
--
$" = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%_ = (Just => another => Perl => Hacker); &{%_};
------------------------------
Date: Thu, 06 Jul 2000 16:24:22 +0100
From: Robert Phillips <R.W.Phillips@cs.cf.ac.uk>
Subject: Re: Going through loops the other way
Message-Id: <3964A4A6.1C028382@cs.cf.ac.uk>
> <> Now I want to change this so that the array is looped from
> <> "finish to start", i.e. the other direction. I thought it would
> <> be a simple matter of doing the following:
>
> Really? What makes you thing that? Did you bother to look up the
> syntax of for()? Then it would be been clear instantly why your
> approach is going to fail.
>
> <> for ($a < @usernames; $a = 0; $a--) {
> <> do stuff
> <> }
> <>
> <> But it doesn't work. Is there a function that will read how long
> <> the array is so that it can start from the last value and work
> <> downwards?
>
> Yes, there is such a "function" and YOU HAVE BEEN USING IT IN BOTH
> CODE FRAGMENTS!
>
> Please, try to understand your own code.
>
> Take your first code fragment. Study it. Learn how it works. If you've
> figured that out, the solution to your problem will be obvious.
>
> (But I'm sure someone will spoonfeed you a canned solution).
>
> Abigail
Whoa! Calm down, love. I will be the first to admit that I am not the world's best
Perl programmer, and I was only asking for a bit of help. I thought this was why the
group was here in the first place. We all have to start somewhere, yes? I bet you
made some pretty silly errors when you just started out! If you're getting tired of
answering simple Perl questions all day, then perhaps you need to take a break. It's
sunny outside (well, at the moment anyway), so soak up some rays and chill out.
From what I read from my code, the following happens:
for ($a = 0; $a < @usernames; $a++)
Reads: starting at 0, go through the document, incrementing $a by 1 until the last
value in the document is reached.
Why is it so ludicrous to think that changing the for loop so that it reads: Start
at the last entry in the document, decrement $a by 1 each time until $a = 0?
To everyone else though, thanks for all your help.
Rob.
------------------------------
Date: Thu, 6 Jul 2000 12:03:32 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Going through loops the other way
Message-Id: <slrn8m9bek.j94.tadmc@magna.metronet.com>
[ Please fix your horrid word-wrap.
Usenet convention is 70-72 characters (so they don't wrap after
being quoted a few times).
]
On Thu, 06 Jul 2000 16:24:22 +0100, Robert Phillips <R.W.Phillips@cs.cf.ac.uk> wrote:
>> <> Now I want to change this so that the array is looped from
>> <> "finish to start", i.e. the other direction. I thought it would
>> <> be a simple matter of doing the following:
>>
>> Really? What makes you thing that? Did you bother to look up the
>> syntax of for()? Then it would be been clear instantly why your
>> approach is going to fail.
>>
>> <> for ($a < @usernames; $a = 0; $a--) {
[snip]
>Whoa! Calm down, love. I will be the first to admit that I am not the world's best
>Perl programmer, and I was only asking for a bit of help.
But you asked _humans_ (*hundreds/thousands* of humans!) before
you even asked a machine for help.
Folks get irritated when asked to do the work of a machine.
It is demeaning. It wastes resources (brain cycles). There
is no advantage to it (unless it is a problem that a
machine _cannot_ find the answer for).
You can ask perl to help you find common mistakes, but you
asked lots of people to help you find it instead.
That is a bad kind of Laziness.
You ask perl for help by enabling warnings with the -w switch.
It says 3 things that all point out what your mistake was:
----------------------------
#!/usr/bin/perl -w
my @usernames = qw/Larry Randal Tom/;
for ($a < @usernames; $a = 0; $a--) {
print "'$a'\n";
}
----------------------------
Found = in conditional, should be == at ./temp line 5.
^^^^^^^^^^^
You swapped the "init" and "test" parts of the for() syntax.
perl is telling you that "$a = 0" is the "test" part.
Useless use of numeric lt (<) in void context at ./temp line 5.
^^^^^^^^^^^^
perl is telling you that the result of "$a < @usernames" was
not used for anything (the result was discarded, so why
calculate the result?).
Use of uninitialized value in numeric lt (<) at ./temp line 5.
perl is telling you that you have never given a value to
the $a in "$a < @usernames" (comparing values when they
have not been given values is a suspicious-looking thing
to do).
>I thought this was why the
>group was here in the first place.
Your thinking is in need of modification. :-)
This is a place to answer questions that cannot be answered
by machines and/or the standard docs.
Answering questions that are easily answered draws time away
from answering questions that are not easily answered.
Somebody did not get their question answered, because the
question answerers were all busy answering _your_ question
(that a machine could have answered).
Posts such as yours injure your peers!
Which is not something usually associated with "community".
Such profound waste is, rather obviously, going to make
folks upset with the cause of the wasted time.
Best to not become associated with a waste of time, because
you may one day have a question that is not easily answered.
>We all have to start somewhere, yes? I bet you
>made some pretty silly errors when you just started out!
Your "silly error" was not enabling warnings.
Just don't do that again. (and "use strict;" will give you yet
more help in finding common mistakes)
>If you're getting tired of
>answering simple Perl questions all day,
I hope by now that you see that it is not tiring of
"simple Perl questions", but rather tiring of
"questions that a machine can answer".
>To everyone else though, thanks for all your help.
^^^^^^^^^^^^^
You inch closer yet to a killfile entry...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 4 Jul 2000 08:31:01 GMT
From: Chris Boyd <cboyd@holyrood.ed.ac.uk>
Subject: Re: Golf problem
Message-Id: <8js7c5$f0l$1@scotsman.ed.ac.uk>
Ilmari Karonen <iltzu@sci.invalid> wrote:
: In article <8jhmcg$5q0s$1@www.univie.ac.at>, Peter Marksteiner wrote:
:>We can save one more stroke by using binary "or":
:>
:>perl -pe '$_=""if/(.).*\1/|11-length' /usr/dict/words
: ..and we can trade off that stroke to fix the Stravinsky problem:
: perl -pe '$_=""if/(.).*\1/i|11-length' /usr/dict/words
This is bizarre. On holyrood.ed.ac.uk (SunOS 5.7), there are several
Perl versions available. Have a look at this (our /usr/dict/words has
no Stravinsky):
$ perl5.001 -pe '$_=""if/(.).*\1/i|11-length' /usr/dict/words | wc
99 99 1089
$ perl5.003 -pe '$_=""if/(.).*\1/i|11-length' /usr/dict/words | wc
99 99 1089
$ perl5.004 -pe '$_=""if/(.).*\1/i|11-length' /usr/dict/words | wc
107 107 1177
The eight extra words are: Andromache Copernicus Ektachrome Gatlinburg
McLaughlin McNaughton Polyphemus Richardson, which all have
Stravinskyness.
On a different (Linux) machine with perl5.00503, the one-liner behaves
correctly.
In other words, the latest Perl version we have available (5.004) gives
a wrong result. Is this a known bug in 5.004? (I couldn't see any
reference to it in man perldelta for 5.00503, but it may have been
described therein in a way I don't understand. I also searched
deja.com, with no obvious previous discussion of this.)
--
No spam please, we're British
------------------------------
Date: Mon, 03 Jul 2000 22:03:59 GMT
From: riemann@home.com
Subject: GPM, ncurses, and other console joy
Message-Id: <j5885.49615$Ey2.342192@news1.sttls1.wa.home.com>
I have a facination with the linux console.
I do not know why but I would rather stare at terminal characters, with no
kerning or variable width spacing, and a limited selection of colors, than
a bloated graphically-arrogant script or even a simple and elegant Tk
script.
I think it is because I work ona mac all day at work desiging brovhures...
Anyway, to the topic. I am working on a collection of modules for the
terminal. The long-term goal is to provide a set of tools which allow you
to write programs for the console, useing Curses (see CPAN), that work like
Tk. I am basing the look and feel on an old module by Ashish Gulhati called
PV (CPAN). A first draft will be available by the end of July.
The sample program distributed with it will be a napster client (hehehe).
Also, as an intermediary step, I have written an interface to gpm that
simply reads output from mev (gpm and mev are programs that allow an
application to interact with the mouse in a unix console). If there is
interest in this, I can post it now.
I am considering modifying William Setzer's curses module to handle mouse
calls based on ncurses functions. ANyone have an opinion on this vs. the
GPM approach?
Is anyone interested at all in the console anymore?
Edward Allen
Riemann@home.com
------------------------------
Date: Mon, 10 Jul 2000 09:04:50 GMT
From: jponder9@my-deja.com
Subject: graphics inserted into pdf
Message-Id: <8kc3jc$95p$1@nnrp1.deja.com>
What I would like to know is: Is there a way of inserting/combining a
graphic file (.gif/.jpg) into a .pdf type file that is generated on the
fly using perl pdf module? I have reviewed the pdf module documentation
but there doesn't appear to be any way of doing the afore mentioned.
Any answers gratefully received.
Many thanks,
J.Ponder
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 10 Jul 2000 12:55:03 GMT
From: Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Subject: Re: graphics inserted into pdf
Message-Id: <8kch37$lkp$1@canopus.cc.umanitoba.ca>
In comp.lang.perl.misc, jponder9@my-deja.com wrote:
> What I would like to know is: Is there a way of inserting/combining a
> graphic file (.gif/.jpg) into a .pdf type file that is generated on the
> fly using perl pdf module? I have reviewed the pdf module documentation
> but there doesn't appear to be any way of doing the afore mentioned.
> Any answers gratefully received.
Check out http://www.pdflib.com/ for the PDFlib library - this
can insert images into a pdf document, and also includes a
perl interface.
best regards,
randy kobes
------------------------------
Date: Thu, 06 Jul 2000 22:13:14 +0800
From: John Hennessy <john@hennessy.net.au>
Subject: Has SNMP replaced Net:SNMP ?
Message-Id: <396493FA.E0DCDDC0@hennessy.net.au>
I have been away from things for a while and have lost touch with the
SNMP module development.
Has the SNMP Perl module replaced the Net:SNMP module I used to use ?
If so where can I find some good examples beyond the perldoc.
I am having trouble with "$sess->set" currently.
Thanks
John.
------------------------------
Date: Mon, 03 Jul 2000 17:23:41 GMT
From: "Ed Foy" <ed@nospam.com>
Subject: Hash keys question
Message-Id: <x_385.26212$NP5.763521@newsread2.prod.itd.earthlink.net>
Greetings,
I am trying to figure out what constitutes a valid hash key name. I have
the perldocs and the Camel book. As best as I can tell a hash key can be
any legitimate Perl string; that is, unlike an identifier (name) it is
not restricted to the pattern /^[A-Za-z_][A-Za-z_0-9]*$/. Is this
correct? I have been unable to find in the docs anything which
explicitly states what constitutes a valid hash key.
Thanks, Ed.
------------------------------
Date: Mon, 03 Jul 2000 14:51:04 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Hash keys question
Message-Id: <39610AC8.13895D44@My-Deja.com>
Ed Foy wrote:
> not restricted to the pattern /^[A-Za-z_][A-Za-z_0-9]*$/. Is this
> correct? I have been unable to find in the docs anything which
> explicitly states what constitutes a valid hash key.
>
Perl requires hash keys to be strings,
so when you use a reference as a key,
Perl uses the reference's string representation
(which will be unique, because it is a pointer value
after all). But when you later retrieve the key
from this hash, it will remain a string and will
thus be unusable as a reference.
------------------------------
Date: Mon, 3 Jul 2000 18:50:33 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hash keys question
Message-Id: <slrn8m265p.d1j.tadmc@magna.metronet.com>
On Mon, 03 Jul 2000 17:23:41 GMT, Ed Foy <ed@nospam.com> wrote:
>I am trying to figure out what constitutes a valid hash key name.
A string.
(strings are usually quoted)
>I have
>the perldocs and the Camel book. As best as I can tell a hash key can be
>any legitimate Perl string;
That's right.
>that is, unlike an identifier (name) it is
>not restricted to the pattern /^[A-Za-z_][A-Za-z_0-9]*$/.
That pattern describes a "bareword".
From perldata:
A word that has no other interpretation in the grammar will
be treated as if it were a quoted string. These are known as
"barewords".
>Is this
>correct?
Yes.
But $hash{key} does not (directly) _have_ a string
for the key.
$hash{'key'} or $hash{"key"}, now _those_ have strings as keys.
With $hash{key} you have a bareword as the key. A bareword
as key is a "special case".
Perl DWIMs the bareword into a string (provide "key" is not
the name of a subroutine that perl has already seen).
>I have been unable to find in the docs anything which
>explicitly states what constitutes a valid hash key.
The very first paragraph of perldata states that:
(5.6) "Hashes are unordered collections of scalar values indexed
by their associated string key."
(5.005_03) "Hash arrays are indexed by string."
So you can have any string as a hash key.
You usually have to quote strings, there is a special case
where you can leave off the quotes though.
It is the special case (of a hash key) that is not documented
(in perldata, where it probably _should be).
There is
"Do I always/never have to quote my strings or use semicolons and commas?"
in Perl FAQ, part 7.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 04 Jul 2000 00:41:56 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Hash keys question
Message-Id: <39623150.2558774@nntp.idsonline.com>
tadmc@metronet.com (Tad McClellan) wrote:
>With $hash{key} you have a bareword as the key. A bareword
>as key is a "special case".
>
>Perl DWIMs the bareword into a string (provide "key" is not
>the name of a subroutine that perl has already seen).
What version of Perl are you using? Earlier versions warned
when the bareword corresponded to a previously defined
subroutine, but they still interpreted it as a string, not an
invocation of the subroutine. Since 5.005, I believe, there
hasn't even been a warning. Surely things haven't changed that
much in 5.6.
So delete the parenthetical addition at the end of the sentence.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Mon, 3 Jul 2000 21:57:32 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hash keys question
Message-Id: <slrn8m2h4c.d5u.tadmc@magna.metronet.com>
On Mon, 03 Jul 2000 14:51:04 -0700, Makarand Kulkarni <makarand_kulkarni@My-Deja.com> wrote:
>
>Ed Foy wrote:
>> not restricted to the pattern /^[A-Za-z_][A-Za-z_0-9]*$/. Is this
>> correct? I have been unable to find in the docs anything which
>> explicitly states what constitutes a valid hash key.
>>
>
>Perl requires hash keys to be strings,
>so when you use a reference as a key,
There was no mention of references in the question.
What do references have to do with answering the question?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 03 Jul 2000 23:44:48 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Hash keys question
Message-Id: <slrn8m2of7.59a.abigail@alexandra.delanet.com>
Tad McClellan (tadmc@metronet.com) wrote on MMCDXCVIII September MCMXCIII
in <URL:news:slrn8m265p.d1j.tadmc@magna.metronet.com>:
**
** But $hash{key} does not (directly) _have_ a string
** for the key.
**
** $hash{'key'} or $hash{"key"}, now _those_ have strings as keys.
**
**
** With $hash{key} you have a bareword as the key. A bareword
** as key is a "special case".
**
** Perl DWIMs the bareword into a string (provide "key" is not
** the name of a subroutine that perl has already seen).
Wrong. $hash{key} *will* use "key" as key, regardless whether Perl
saw it as name of a subroutine. What's between the curly braces
isn't subject to the bareword behaviour (which you can't do with
use strict; in effect, and -w complains too), but to auto quoting
behaviour. That is, if it looks like a valid identifier, it will
be a string.
Abigail
--
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print
qq{Just Another Perl Hacker\n}}}}}}}}}' |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w
------------------------------
Date: Mon, 10 Jul 2000 19:45:24 +0200
From: "nicolas" <webmaster@archiTacTic.com>
Subject: Hash vs. Array memory usage
Message-Id: <0Zna5.15609$DL.65529@nnrp1.none.net>
Is there a way to know the memory usage of a variable?
I have some very large variables (flat lists) that can be put in an array
(@MyBigVar), or in a Hash (%MyBigVar) and would like to know the memory size
of each to decide which is better.
Thanks,
Nick
------------------------------
Date: Fri, 07 Jul 2000 21:07:52 GMT
From: boris_kitsis@my-deja.com
Subject: Have you seen this apache error?
Message-Id: <8k5gr0$6nb$1@nnrp1.deja.com>
We are running our site on apache mod_perl. And we are experiencing
this weird problem. Server runs really well for a while, but then it
starts spitting out these errors:
Can't undef active subroutine
at /usr/local/lib/perl5/site_perl/5.6.0/i686-linux/Apache/Registry.pm
line 108.
We can't seem to figure out what the cause would be, so if you have
seen this somewhere before and know what causes it, we would greatly
appreciate the feedback. The problem temporarily gets fixed when we
restart the server, but it certainly is not a fix for the longhaul.
Another issue with the server is that some ODBC connections don't get
retired and after a while the server starts refusing connection since
it has too many open. Restarting the apache server takes care of that
too. Any feedback on this?
Thank you in advance,
Boris
borisk@auctionet.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 07 Jul 2000 22:30:37 GMT
From: ramagoon@yahoo.com
Subject: Help - FTP scripting with Perl on Win32
Message-Id: <8k5lme$9q5$1@nnrp1.deja.com>
Currently, our servers transfer files via FTP between AIX and NT Server
4 boxes. We use NT's built-in FTP scripting functionality. All ftp
sessions are appended to a log file for troubleshooting.
I am not impressed with NT's way of FTP'ing through batch. It's error
recovery is none, and the passwords are not encrypted.
Is there anything I can do with Perl and the Win32 extensions? If there
is, can someone point me to an example?
Thanx folks!
-Rick
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 7 Jul 2000 23:25:22 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Help - FTP scripting with Perl on Win32
Message-Id: <8k5ot2$qd4$7@slb6.atl.mindspring.net>
ramagoon@yahoo.com wrote:
: Currently, our servers transfer files via FTP between AIX and NT Server
: 4 boxes. We use NT's built-in FTP scripting functionality. All ftp
: sessions are appended to a log file for troubleshooting.
:
: I am not impressed with NT's way of FTP'ing through batch. It's error
: recovery is none, and the passwords are not encrypted.
:
: Is there anything I can do with Perl and the Win32 extensions? If there
: is, can someone point me to an example?
Grab Net::FTP (it's part of libnet, available from ActiveState and CPAN)
and take a look at its documentation. It will probably do everything you
want.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3565
**************************************