[13392] in Perl-Users-Digest
Perl-Users Digest, Issue: 802 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 15 12:17:22 1999
Date: Wed, 15 Sep 1999 09:10:35 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 15 Sep 1999 Volume: 9 Number: 802
Today's topics:
Concurrency / File locking in CGI-Operations <krajzewicz@inx.de>
Re: Concurrency / File locking in CGI-Operations <rootbeer@redcat.com>
Re: Critique/comments for web board? (Eric Bohlman)
Re: EAGAIN - any ideas why? (Lack Mr G M)
Re: Error in "Learning Perl, 2nd Edition" or Error in P (Abigail)
Re: Error in "Learning Perl, 2nd Edition" or Error in P <rhomberg@ife.ee.ethz.ch>
Re: Error in "Learning Perl, 2nd Edition" or Error in P (Randal L. Schwartz)
Re: Error in "Learning Perl, 2nd Edition" or Error in P (Brian Clark)
Re: Error in "Learning Perl, 2nd Edition" or Error in P <uri@sysarch.com>
Re: Error in "Learning Perl, 2nd Edition" or Error in P (Randal L. Schwartz)
Re: Error in "Learning Perl, 2nd Edition" or Error in P (Randal L. Schwartz)
Re: Faxing Script <jerryp.usenet@connected.demon.co.uk>
Re: Filtering ascii escape sequences in a text file <wpflum@my-deja.com>
financial calculator <cf@point-infotec.de>
Re: financial calculator (Matthew Bafford)
Re: Forcing Variable interpolation of string read from (Eric Bohlman)
Giving names to arrays automatically <m.scheferhoff@gmx.de>
Re: Giving names to arrays automatically <gellyfish@gellyfish.com>
Re: Giving names to arrays automatically <mike@crusaders.no>
Re: Giving names to arrays automatically (Larry Rosler)
Re: Help - Porting code from UNIX to NT <ehpoole@ingress.com>
HELP PARSE EMAIL ADDRESSES PLEASE (Joe Snow)
Re: HELP PARSE EMAIL ADDRESSES PLEASE <rootbeer@redcat.com>
Help! .pm did not return a true value (Roman Prokhorov)
Re: Help! Need to check <rhomberg@ife.ee.ethz.ch>
Re: how to hide secured info? <rootbeer@redcat.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 15 Sep 1999 09:55:43 +0200
From: Daniel Krajzewicz <krajzewicz@inx.de>
To: Daniel Krajzewicz <krajzewicz@inx.de>
Subject: Concurrency / File locking in CGI-Operations
Message-Id: <37DF50FF.3E26E8D6@inx.de>
Hello there !!
I'm using a script which sreads in the side it's called by...
Well, actually I'd just like to know if I have to lock it on reading
(the file).
Personally I don't think so, it should be read by each process for it
own without any concurreny problems. Is that right ??
thanks,
Daniel Krajzewicz
--
__________________________
< Daniel Krajzewicz >
>------------------------<
< krajzewicz@inx.de >
>------------------------<
< http://www.art-so-far.de >
>------------------------<
<__________________________>
------------------------------
Date: Wed, 15 Sep 1999 06:40:08 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Concurrency / File locking in CGI-Operations
Message-Id: <Pine.GSO.4.10.9909150636170.25903-100000@user2.teleport.com>
On Wed, 15 Sep 1999, Daniel Krajzewicz wrote:
> Well, actually I'd just like to know if I have to lock it on reading
> (the file).
If the file's contents never change, there are no concurrency issues, so
locking isn't needed. If anyone might be updating the file while another
program is reading or writing, then you want locking. Every process which
is (only) reading the file should get a shared lock, and every process
which is updating the file should get an exclusive lock.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 15 Sep 1999 09:25:34 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Critique/comments for web board?
Message-Id: <7rnome$ho2@dfw-ixnews19.ix.netcom.com>
David Wall (darkon@one.net) wrote:
: I wrote a little web BBS (in Perl, of course) for fun, and have it posted at
: http://w3.one.net/~darkon/darkboard/. It's nothing fancy, just a toy project,
: but if anyone here would like to take a look at it and offer useful
: suggestions on improving my code, I'd appreciate it. I'm not a professional
: programmer, so it's entirely possible that I may be doing things the hard way
: when there's a pre-existing method. Of course, I may have just done some
: stupid things in my code. In any case, I tried to comment it so that it could
: be read easily.
:
: So... comments, anyone?
Based on a very cursory examination:
1) You've got a concurrency problem when you're posting a message because
GetIndex() opens the index file, locks it, reads it and then closes it
(clearing the lock), you make some changes, and then call WriteIndex()
which again opens the file, locks it, writes out the changes, and closes
it. The problem is that in between the GetIndex and the WriteIndex(),
another copy of your program can come along and read the index file, which
won't yet have any of the changes you're in the process of making, and
proceed to make *its* changes. If it writes them out before the first
copy gets control again, the first copy will undo the changes; if the
first copy gets control first, the second copy will undo the changes the
first copy made.
If you're going to read a file, make some changes, and then rewrite the
file, you have to keep that file locked for the entire duration, not just
the reading and writing phases. Your desire to segregate the reading and
writing of the file into "black box" procedures is praiseworthy, but in
this case it prevents maintaining the lock. One way to avoid duplicating
code would be to have GetIndex take an argument which specifies whether
or not to close the file after reading it; you'd set this to true if you
were reading the index just to display a message, and false if you were
reading it with the intention of updating it. WriteIndex would then
assume that the file was already open, and would do the appropriate
seeking and truncating.
2) You're using symbolic references just to reduce typing. This is a
false economy. Use a hash instead, and use strict.
3) You could use here-document syntax in a lot more places than you
presently are.
4) In your date-printing code, there are a couple places where you use an
if statement to zero-pad numbers. Use sprintf or printf instead.
The concurrency problem is the major issue I see, and your code is a lot
better-structured than many common CGI scripts.
------------------------------
Date: Wed, 15 Sep 1999 10:52:02 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: EAGAIN - any ideas why?
Message-Id: <1999Sep15.105202@ukwit01>
In article <1999Sep15.100413@ukwit01>, gml4410@ggr.co.uk (Lack Mr G M) writes:
|>
|> I have a Netscape Proxy server (v2.5x) running on a dual-processor
|> O200.
PLEASE IGNORE (wrong newsgroup...)
Sorry....
--
--------- Gordon Lack --------------- gml4410@ggr.co.uk ------------
This message *may* reflect my personal opinion. It is *not* intended
to reflect those of my employer, or anyone else.
------------------------------
Date: 14 Sep 1999 23:48:54 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Error in "Learning Perl, 2nd Edition" or Error in Perl port specific to Windows or ?
Message-Id: <slrn7tu9ed.gcd.abigail@alexandra.delanet.com>
Ishmael (jgrot@spam.off.tso.cin.ix.net) wrote on MMCCVI September
MCMXCIII in <URL:news:rtu61aj71iv59@corp.supernews.com>:
\\ Brian,
\\
\\ The script as copied from your message worked as advertised for me. See
\\ sample output below. I am using version 5.005_03 ActiveState build 518.
\\
\\ Jeff
\\
\\ chomp(@words = <STDIN>);
\\ foreach $word (@words) {
\\ $count{$word} = $count{$word} + 1;
\\ }
\\ foreach $word (keys %count) {
\\ print "$word was seen $count{$word} times!\n";
\\ }
Why a foreach keys, and then getting the value in the block? Clever use of
command line switches can turn the above in:
perl -wnle '$c {$_} ++;
END {while (($w, $c) = each %c) {print "$w was seen $c times!"}'
Abigail
--
perl -wleprint -eqq-@{[ -eqw+ -eJust -eanother -ePerl -eHacker -e+]}-
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 15 Sep 1999 12:37:22 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Error in "Learning Perl, 2nd Edition" or Error in Perl port specific to Windows or ?
Message-Id: <37DF76E2.44E621FC@ife.ee.ethz.ch>
Abigail wrote:
> Why a foreach keys, and then getting the value in the block? Clever use of
> command line switches can turn the above in:
Because he mentioned something like 'new to Perl' and 'copied from the
book'
While your line is cool stuff (once corrected so it runs), it is
probably not newbie material
> perl -wnle '$c {$_} ++;
> END {while (($w, $c) = each %c) {print "$w was seen $c times!"}'
You seem to slowly make the transition from }{ to END.. Too slowly as my
perl is complains about a missing bracket..
- Alex
------------------------------
Date: 15 Sep 1999 07:35:24 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Error in "Learning Perl, 2nd Edition" or Error in Perl port specific to Windows or ?
Message-Id: <m19068cker.fsf@halfdome.holdit.com>
>>>>> "Abigail" == Abigail <abigail@delanet.com> writes:
Abigail> Why a foreach keys, and then getting the value in the block? Clever use of
Abigail> command line switches can turn the above in:
Abigail> perl -wnle '$c {$_} ++;
Abigail> END {while (($w, $c) = each %c) {print "$w was seen $c times!"}'
Because a second part of the exercise is "now sort by keys".
Hard to do with each().
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 15 Sep 1999 14:57:05 GMT
From: perl@bjclark.com (Brian Clark)
Subject: Re: Error in "Learning Perl, 2nd Edition" or Error in Perl port specific to Windows or ?
Message-Id: <37dfb0be.67363578@news.greenwood.net>
On Wed, 15 Sep 1999 12:37:22 +0200, Alex Rhomberg
<rhomberg@ife.ee.ethz.ch> wrote:
>Abigail wrote:
>
>> Why a foreach keys, and then getting the value in the block? Clever use of
>> command line switches can turn the above in:
>
>Because he mentioned something like 'new to Perl' and 'copied from the
>book'
>While your line is cool stuff (once corrected so it runs), it is
>probably not newbie material
>
>> perl -wnle '$c {$_} ++;
>> END {while (($w, $c) = each %c) {print "$w was seen $c times!"}'
>
>You seem to slowly make the transition from }{ to END.. Too slowly as my
>perl is complains about a missing bracket..
-----
For some reason, I never see Abigail's posts. I have read many
messages/replies with Abigail's quoted text, but I never get Abigail's
actual message.
A followup to my original post:
I got Jeff's message, and I decided to go ahead and upgrade to
ActiveState's 519 Build. I did that, and I still get the same output
from the example in my original post.
I have tried this with two different builds of ActiveState's Perl on
two different systems and three different systems total:
Win95B (first posting), BSDI 4.0.1 (first posting), and now Win98
(This may not make and difference what-so-ever, I don't know).
Are there _any_ more ideas of what might be the problem with that code
running correctly on the Win32 platform? (This is a serious inquiry;
I'm not trying to start a holy war.)
Brian
------------------------------
Date: 15 Sep 1999 11:13:55 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Error in "Learning Perl, 2nd Edition" or Error in Perl port specific to Windows or ?
Message-Id: <x7puzkjjgs.fsf@home.sysarch.com>
>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
>>>>> "Abigail" == Abigail <abigail@delanet.com> writes:
Abigail> perl -wnle '$c {$_} ++;
Abigail> END {while (($w, $c) = each %c) {print "$w was seen $c times!"}'
RLS> Because a second part of the exercise is "now sort by keys".
RLS> Hard to do with each().
nahhh!
i have sorted the output of each like this:
END {push @l, sprint "$w was seen $c times!\n" while ($w, $c) = each %c;
print sort @l}
saves all those pesky little hash lookups.
each is underused.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: 15 Sep 1999 08:54:24 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Error in "Learning Perl, 2nd Edition" or Error in Perl port specific to Windows or ?
Message-Id: <m13dwgb26n.fsf@halfdome.holdit.com>
>>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes:
>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:
Uri> END {push @l, sprint "$w was seen $c times!\n" while ($w, $c) = each %c;
Uri> print sort @l}
Randal> Uh... sprint is the long distance phone company.
Randal> You need to use the floating-point version of that... "sprintf".
Randal> :-)
And now that I think of it, you really didn't want a -f version anyway!
"doh!"
The "sprint" function, takes a string and turns it into... a... string... :)
So, would have been simpler to:
push @l, "$w was seen $c times!\n" while ($w, $c) = each %c;
Gah.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 15 Sep 1999 08:52:06 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Error in "Learning Perl, 2nd Edition" or Error in Perl port specific to Windows or ?
Message-Id: <m17llsb2ah.fsf@halfdome.holdit.com>
>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:
Uri> END {push @l, sprint "$w was seen $c times!\n" while ($w, $c) = each %c;
Uri> print sort @l}
Uh... sprint is the long distance phone company.
You need to use the floating-point version of that... "sprintf".
:-)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 15 Sep 1999 06:07:11 +0100
From: Jerry Pank <jerryp.usenet@connected.demon.co.uk>
Subject: Re: Faxing Script
Message-Id: <ogx1tDA$ly33Ewaw@btinternet.com>
In <comp.lang.perl.misc>
Michael Budash <mbudash@sonic.net>, writes:
>In article <19990914093726.01474.00000040@ng-cp1.aol.com>,
>bbirthisel@aol.com (Bbirthisel) wrote:
>
>>Hi Martien and Rich:
>>
>>>For win32 you should be able to treat your fax as a printer, but how
>>>you pass it the required parameters is specific to the software etc.
>>>Maybe ActiveState has some win32 specific faxing modules.
<snip>
It's not a Perl solution but it works for me:
http://www.tpc.int/ Free email to fax gateway.
-- Jerry Pank:wq http://www.netconnected.com/
jerryp.usenet@netconnected.com
: How would you disambiguate these situations?
By shooting the person who did the latter.
-- Larry Wall in <199710290235.SAA02444@wall.org>
------------------------------
Date: Wed, 15 Sep 1999 11:43:21 GMT
From: Bill <wpflum@my-deja.com>
Subject: Re: Filtering ascii escape sequences in a text file
Message-Id: <7ro0on$86r$1@nnrp1.deja.com>
Looked good until I tried it. When I cat the file to col I get no
output whatsoever. If I do cal|col I get an output so I'm sure col is
working just not sure what its doing to my dump file. Looks like its
removing everything, plain text included. Any ideas??
In article <37deb612@cs.colorado.edu>,
tchrist@mox.perl.com (Tom Christiansen) wrote:
> [courtesy cc of this posting mailed to cited author]
>
> In comp.lang.perl.misc,
> Bill <wpflum@my-deja.com> writes:
> :I'm looking for either a module or a script that will filter out
ascii
> :escape sequences from a text file. I'd rather not re-invent the wheel
> :if this has been done already.
>
> % man col | col -b
>
> COL(1) UNIX Reference Manual
COL(1)
>
> NAME
> col - filter reverse line feeds from input
>
> SYNOPSIS
> col [-bfx] [-l num]
>
> DESCRIPTION
> Col filters out reverse (and half reverse) line feeds so the
output is in
> the correct order with only forward and half forward line feeds,
and re-
> places white-space characters with tabs where possible. This
can be use-
> ful in processing the output of nroff(1) and tbl(1).
>
> Col reads from standard input and writes to standard output.
>
> The options are as follows:
>
> -b Do not output any backspaces, printing only the
last character
> written to each column position.
>
> -f Forward half line feeds are permitted (``fine''
mode). Normally
> characters printed on a half line boundary are printed on
the fol-
> lowing line.
>
> -x Output multiple spaces instead of tabs.
>
> -lnum Buffer at least num lines in memory. By default, 128
lines are
> buffered.
>
> The control sequences for carriage motion that col understands
and their
> decimal values are listed in the following table:
>
> ESC-7 reverse line feed (escape then 7)
> ESC-8 half reverse line feed (escape then 8)
> ESC-9 half forward line feed (escape then 9)
> backspace moves back one column (8); ignored in the
first column
> carriage return (13)
> newline forward line feed (10); also does carriage return
> shift in shift to normal character set (15)
> shift out shift to alternate character set (14)
> space moves forward one column (32)
> tab moves forward to next tab stop (9)
> vertical tab reverse line feed (11)
>
> All unrecognized control characters and escape sequences are
discarded.
>
> Col keeps track of the character set as characters are read and
makes
> sure the character set is correct when they are output.
>
> If the input attempts to back up to the last flushed line, col
will dis-
> play a warning message.
>
> SEE ALSO
> expand(1), nroff(1), tbl(1)
>
> HISTORY
> A col command appeared in Version 6 AT&T UNIX.
>
> BSD Experimental June 17, 1991
1
> --
> A computer scientist is someone who, when told to "Go to Hell," sees
> the "go to," rather than the destination, as harmful.
> -- Dr. Roger M. Firestone, rfire@cais.cais.com
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 15 Sep 1999 12:57:29 +0200
From: Christoph Faak <cf@point-infotec.de>
Subject: financial calculator
Message-Id: <37DF7B99.A2A42C77@point-infotec.de>
Hi,
i´m searching for a cgi-based financial-calculator, who knows an URL or
has such a script. Help please!!!
thanx and greetings
Torsten Schmidt
t.schmidt@ndh.net
------------------------------
Date: Wed, 15 Sep 1999 12:11:37 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: financial calculator
Message-Id: <slrn7tv122.1pj.*@dragons.duesouth.net>
On Wed, 15 Sep 1999 12:57:29 +0200, Christoph Faak <cf@point-infotec.de>
spewed forth:
: Hi,
:
: i´m searching for a cgi-based financial-calculator,
We help you with programming problems here.
Search engines help you find things.
comp.lang.perl.misc is not a search engine.
: who knows an URL or has such a script.
Then why aren't you asking who? If he knows, then he seems to be the
most obvious choice...
: Help please!!!
Try:
http://www.yahoo.com/
http://www.altavista.com/
http://www.cgi-resources.com/
: thanx and greetings
Good Luck!
: Torsten Schmidt
--Matthew
------------------------------
Date: 15 Sep 1999 09:52:56 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Forcing Variable interpolation of string read from a file - How?
Message-Id: <7rnq9o$ho2@dfw-ixnews19.ix.netcom.com>
Tom Christiansen (tchrist@mox.perl.com) wrote:
: [courtesy cc of this posting mailed to cited author]
:
: In comp.lang.perl.misc,
: matthias.schwarze@wiesbaden.netsurf.de writes:
: :I don't think that the direct interpolation (if possible at all?!) is
: :advisable.
:
: What I want to understand is why this question *NEVER* comes up amongst
: C programmers, but the Perl neophytes seem to ask it as often as rises
: the sun. Perhaps it's some issue of mismatched mental models.
Just a guess; C is rarely someone's first programming language, so by the
time they learn it, they've had some exposure to data-structure
concepts. OTOH, there are a lot of people using Perl without having
learned the sorts of things taught in an introductory programming course;
they may never have encountered the notion of an array, either one
indexed numerically or one indexed symbolically.
There was a recent discussion (still ongoing) on the xml-dev list about
groves as data models, and somebody pointed out that many people doing
Web support programming have little to no exposure to data structures
beyond simple arrays; things like trees are extremely advanced topics for
them.
Someone else pointed out (I believe in a thread on c.i.w.a.cgi) that most
good introductory Perl material (like _Learning Perl_) devotes a bunch of
space up front to data types such as scalars, arrays and hashes, but too
many beginning programmers find it too boring or theoretical and skip
over it, unnecessarily limiting their understanding of the language. Now
I've always believed that you have to be able to play with Perl before
you can work with it, and I see nothing wrong with skipping over such
introductory material *the very first time* and starting to play. But
that only works if you have the mental discipline to *come back to* the
stuff you skipped over *well before* you start trying to *work* with
Perl.
Too many people seem to be omitting that step; they want to read the
tutorials only once, but they also want to skip over parts. I don't know
if that's just mental laziness, or the result of an "education" system
that teaches people that learning is an unpleasant chore to be gotten over
with as quickly as possible (partly out of fear that if people don't think
of learning as painful, they'll learn things that the people in authority
would rather they not learn). It may be the result of people who have no
interest in writing programs having the task of programming forced on
them, and fighting the learning process rather than getting engaged in it.
Whatever the reason, this attitude leads to a predictable result: no time
to do it right in the first place, but plenty of time wasted trying to fix
it later.
------------------------------
Date: Wed, 15 Sep 1999 15:05:45 +0200
From: Michael Scheferhoff <m.scheferhoff@gmx.de>
Subject: Giving names to arrays automatically
Message-Id: <37DF99A9.65FA573B@gmx.de>
Hello,
I want to create new arrays and give them names automatically in a loop.
Does anybody know how to realisate this?
Thanks,
Michael
------------------------------
Date: 15 Sep 1999 14:23:46 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Giving names to arrays automatically
Message-Id: <37df9de2_2@newsread3.dircon.co.uk>
Michael Scheferhoff <m.scheferhoff@gmx.de> wrote:
> Hello,
>
> I want to create new arrays and give them names automatically in a loop.
> Does anybody know how to realisate this?
>
Yes I do but I am not going to tell how to do it - instead I am going
to recommend you to use a hash of arrays - keyed on whatever string it is
you would be naming the different arrays.
/J\
--
"Killing myself is the last thing I'd ever do" - Homer Simpson
------------------------------
Date: Wed, 15 Sep 1999 15:29:07 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: Giving names to arrays automatically
Message-Id: <HaND3.281$uV5.1802@news1.online.no>
Michael Scheferhoff <m.scheferhoff@gmx.de> wrote in message
news:37DF99A9.65FA573B@gmx.de...
> I want to create new arrays and give them names automatically in a
loop.
> Does anybody know how to realisate this?
Well, it is probably possible to do this with @{$name}, but it is IMHO
much, much, better to assign a reference to an array to a hash-key.
-----------8<--------------
#!/local/bin/perl -w
use strict;
my %HASH;
for (qw/foo bar baz/){
my $n;
for $n (1..5) {
push @{ $HASH{$_} }, rand 10;
}
}
my $key;
foreach $key (keys %HASH) {
print "$key:\n";
my $arrayref = $HASH{$key};
for (@$arrayref){
print " $_\n";
}
print "\n";
}
__END__
-----------8<--------------
As you see. This makes it possible to fetch all the arrays you have
generated without actually knowing their names.
If you want to play around with references, you'll probably find the
perlref manual to be helpful.
perldoc perlref
--
Trond Michelsen
------------------------------
Date: Wed, 15 Sep 1999 06:53:37 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Giving names to arrays automatically
Message-Id: <MPG.124944bb3e759ba2989f68@nntp.hpl.hp.com>
In article <37DF99A9.65FA573B@gmx.de> on Wed, 15 Sep 1999 15:05:45
+0200, Michael Scheferhoff <m.scheferhoff@gmx.de> says...
> I want to create new arrays and give them names automatically in a loop.
> Does anybody know how to realisate this?
Yes, I know how to realize this. But I won't tell you, because creating
symbols dynamically is poor practice.
Add entries to an array of array references or to a hash of array
references.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 15 Sep 1999 02:17:05 -0400
From: "Ethan H. Poole" <ehpoole@ingress.com>
Subject: Re: Help - Porting code from UNIX to NT
Message-Id: <37DF39E1.506DEE25@ingress.com>
David Cassell wrote:
>
> And NT [along with the webserver] only knows what to do with
> the file extension after some careful explanation. If you're
> lucky, ActiveState got it all done for you. If not, prepare
> to start reading the documentation.
Really not necessary to do much reading, one small section in the perl
docs, and one simple screen in the IIS admin interface.
.pl -> c:\perl\bin\perl.exe "%s" "%s"
Now they don't have to read the docs, they just have to find the
Extensions screen.
--
Ethan H. Poole **** BUSINESS ****
ehpoole@ingress.com ==Interact2Day, Inc.==
(personal) http://www.interact2day.com/
------------------------------
Date: Wed, 15 Sep 1999 07:03:26 -0500
From: joesnow@mindspring.com (Joe Snow)
Subject: HELP PARSE EMAIL ADDRESSES PLEASE
Message-Id: <joesnow-1509990703300001@user-2ivebks.dialup.mindspring.com>
#!perl -p
while (<>) {
if (s/(^.*\s)(\S+\@\S+)(\s.*$)/\2\n/g)
{
print "$_";
}
}
#how can I make the next lines operate on my script; line by line while (<>)
s/^(email|e-mail)(:|-|\s)(.*)/\3/gi;
s/(^\n)//g
------------------------------
Date: Wed, 15 Sep 1999 07:47:07 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: HELP PARSE EMAIL ADDRESSES PLEASE
Message-Id: <Pine.GSO.4.10.9909150739300.25903-100000@user2.teleport.com>
On Wed, 15 Sep 1999, Joe Snow wrote:
> Subject: HELP PARSE EMAIL ADDRESSES PLEASE
Maybe you want section nine of the FAQ: "How do I check a valid email
address?"
> #!perl -p
>
> while (<>) {
If you're using -p, you probably don't want this while loop.
> if (s/(^.*\s)(\S+\@\S+)(\s.*$)/\2\n/g)
My friends Fred and Barney would like you to write to them at this
address:
<"fred and barney"(yes, spaces are okay in addresses)@redcat.com>
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 15 Sep 1999 17:00:12 +0400
From: roma@stalker.gamma.ru (Roman Prokhorov)
Subject: Help! .pm did not return a true value
Message-Id: <roma-1509991700120001@node4.stalker.gamma.ru>
Hi!
On one of my customer's machine my scripts don't run:
---
CLI.pm did not return a true value at ./ListAccounts.pl line 13.
BEGIN failed--compilation aborted at ./ListAccounts.pl line 13.
---
Line 13 is "use CLI.pm;". The CLI.pm has "1;" on its end and it works
fine on all platforms except that particular machine.
What can I do about it? Please answer by e-mail if possible.
--
Roma
------------------------------
Date: Wed, 15 Sep 1999 11:08:19 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Help! Need to check
Message-Id: <37DF6203.B878A8E5@ife.ee.ethz.ch>
David Cassell wrote:
> > @new = ();
>
> my new;
my @new;
> > @old = 1 .. 51; # just a demo
>
> my @old = 0 .. 51;
>
> Why are you starting arrays at 1 instead of 0 ?
Probably because they are not array indices but values? and because
lotto
numbers are in the range 1..51 and rarely start at zero?
> I appreciate your attempt to help, but could you:
> [1] adhere to newsgroup standards;
> [2] post tested, correct code; and
> [3] not post answers previously dissed in the same thread?
I'll drink to that and add:
[4] do not post code that works but produces different results
[5] adhere to one's standard as told others
To go back to the question, here's my code:
(faster with splice than with shuffle with these sizes)
#!/usr/bin/perl -w
#prints six different random numbers in the range 1..51
use strict;
my @new;
my @old=(1..51);
for (1..6) {
push @new, splice @old, rand @old, 1;
}
print "@new\n";
- Alex
------------------------------
Date: Wed, 15 Sep 1999 05:46:33 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: how to hide secured info?
Message-Id: <Pine.GSO.4.10.9909150544060.25903-100000@user2.teleport.com>
On Tue, 14 Sep 1999 jloved@my-deja.com wrote:
> I want to hide oracle login id and password in perl code. Is it
> possible?
No. Instead, you may wish to put the secret info into a file readable only
by its owner, then use a set-id program to do the work. See the perlsec
manpage for more details. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu.
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 802
*************************************