[13236] in Perl-Users-Digest
Perl-Users Digest, Issue: 646 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 25 22:07:46 1999
Date: Wed, 25 Aug 1999 19:05:08 -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, 25 Aug 1999 Volume: 9 Number: 646
Today's topics:
Re: Converting strings to arrays question <makkulka@cisco.com>
Re: DB_File cause my scripts to run slower? (Martien Verbruggen)
Re: Excel file from Perl <jeff@vpservices.com>
Re: loop through a hash of arrays based on array elemen (Bill Moseley)
Re: loop through a hash of arrays based on array elemen (Larry Rosler)
mirror.pl on OS/2 Question <huffd@nls.net>
Re: Newbie ?: Function Arguments and Arrays (Martien Verbruggen)
Re: Perl a Black Sheep? (Eric Bohlman)
Re: Perl on NT vs Perl on Win98 <wyzelli@yahoo.com>
Re: Regex Question (Larry Rosler)
Re: REQ: tell-a-friend script (Abigail)
Re: Select Multiple Form Field via Perl into Oracle err <makkulka@cisco.com>
Server Side Include Parameters <eroby@webpositioning.com>
Re: Sorting a list of lists (Abigail)
Re: The extent of double-quotish interpolation (Alan Curry)
Re: VERY VERY VERY weird things happening (Bill Moseley)
Re: What are valid characters in hash keys (Abigail)
Re: What are valid characters in hash keys (Dave Regan)
Re: What are valid characters in hash keys (Larry Rosler)
YAREQ (yet another regexp question) (Bill Moseley)
YAREQ (yet another regexp question) (Bill Moseley)
Re: YAREQ (yet another regexp question) (Larry Rosler)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 25 Aug 1999 17:01:14 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Converting strings to arrays question
Message-Id: <37C483CA.FA1EC4C2@cisco.com>
[ Ilya wrote:
> The perl/CGI script
> sets the parameters that the user wants to look at. I run a bunch of scripts
> to take sar data collected over the last few months and each array,
> i.e. @cpu_usr holds numbers that represent one line on the graph. Since they
> user may not want to look at all the variables, he chooses the ones he wants.
> Depending on the ones the user wants, I set $cpu_usr (and many others) to a
> value. If the value of $cpu_usr is zero, then I know that the user does not
> want to look at @cpu_usr array based on sar.
> So:
> foreach $value (values (%input_params))
> {
> if ($value ne 0) # we have an array that the user wants to examine
> {
> push (@data, @value)
> }
> }
>
> Then @data is used to dynamicaly build a GIF graph.
Maintain a hash whose values are array refs ( this array maps to one line
on the graph ) and whose keys are the values that $value variable can contain.
%Mapper = (
value1 => [ 1, 2, 3, 4 ..],
value2=> [ 23, 23, 34,...],
etc
);
foreach $value (values (%input_params))
{
push (@data, @{ $Mapper{$value}}) if ( $value ne 0 );
}
--
------------------------------
Date: Thu, 26 Aug 1999 00:07:51 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: DB_File cause my scripts to run slower?
Message-Id: <rz%w3.3091$hf4.39254@nsw.nnrp.telstra.net>
In article <37C47453.B1766249@americasm01.nt.com>,
"Chaudhry, Asad" <vc13stu1@americasm01.nt.com> writes:
> I'm using DB_File to tie large arrays and hashes. I find that my scripts
> run slower when I tie my data with DB_File as opposed to using ordinary
> arrays and hashes within perl.
[snip]
> My question is: Is there away to increase performance, or is this a
> trade-off for using DB_File?
Well, DB_File stores your hash on disk, so accesses to the hash mean
accesses to the file system. Speed improvements may come from more
memory (file system cache larger), but then, if you had enough memory,
you'd probably be using an in-memory hash.
You could also try some of the other dbm ties, although I sincerely
doubt that that will improve speed significantly.
Martien
--
Martien Verbruggen |
Interactive Media Division | In the fight between you and the world,
Commercial Dynamics Pty. Ltd. | back the world - Franz Kafka
NSW, Australia |
------------------------------
Date: 25 Aug 1999 23:05:18 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Excel file from Perl
Message-Id: <37C475B6.4BE93A1F@vpservices.com>
You can use DBI with DBD::Oracle to get the data and DBD::CSV to create
comma-separated-values files. Excel can read the CSV files directly.
--
Jeff
Michael Hill wrote:
>
> I have some perl scripts that create HTML tables from and Oracle DB.
> However some users want me to send then and excel file. Anyone have any
> exemples of this?
>
> Mike
------------------------------
Date: Wed, 25 Aug 1999 17:38:23 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: loop through a hash of arrays based on array element?
Message-Id: <MPG.122e2c5683e641c89896d3@nntp1.ba.best.com>
Alec Kelingos (akelingos@petrosys-usa.com) seems to say...
> How can I sort a hash of arrays based on one of the array elements? For
> example, I have a hash
In the FAQ:
How do I sort an array by (anything)?
Gives an example
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: Wed, 25 Aug 1999 18:02:40 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: loop through a hash of arrays based on array element?
Message-Id: <MPG.122e3206849b95bb989ea3@nntp.hpl.hp.com>
In article <37C4718F.C72E04C7@earthlink.net> on Wed, 25 Aug 1999
15:43:27 -0700, Joe Schmoe <dont_ever.spam_pvoris@earthlink.net> says...
> Assuming I understand you correctly (meaning that you want to sort the
> keys by element [4] of the arrays whose references the keys are
> associated with), try this:
>
> #!/usr/bin/perl -w
> use strict;
>
> my %columns = (
> 'API' => ['A', 1, 14, 'STR', 1],
> 'LATITUDE' => ['A', 2, 9, 'LAT', 2],
> 'LONGITUDE' => ['A', 3, 20, 'LON', 3],
> 'TD_FORM' => ['A', 4, 8, 'STR', 4],
> 'PR_FORM' => ['A', 5, 8, 'STR', 5],
> 'STATUS' => ['A', 8, 6, 'STR', 6]
> );
>
> foreach ( sort { $columns{$a}[4] cmp $columns{$b}[4] } keys %columns ) {
> print "$_\n";
> }
I hope there are always fewer than 10 elements in the hash.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 26 Aug 1999 00:53:11 GMT
From: "David D. Huff Jr." <huffd@nls.net>
Subject: mirror.pl on OS/2 Question
Message-Id: <37C48EAB.6E3177F3@nls.net>
How do I make mirror.pl delete files on the target
server that do not exist on the source server?
I am mirroring a server that deletes outdated
files. Mirror.pl does not delete the files on my
OS/2 server it tries to unlink then it says it
cannot find the file/directory.
Thanks
------------------------------
Date: Thu, 26 Aug 1999 00:37:52 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Newbie ?: Function Arguments and Arrays
Message-Id: <A%%w3.3125$hf4.39867@nsw.nnrp.telstra.net>
In article <37C46084.73805D43@kalfas.com>,
Thomas Kalfas <thomas@kalfas.com> writes:
> This is my first experience with perl, and I'm sorry if this is not the
> appropriate place for this question, but I need some assistance with
It is the appropriate place.
> I'm trying to use the system() function to mv FILEA to FILEB but I keep
You should most likely not do that. The rename() builtin will do in
most cases what you need (but it won't move files across file system
boundaries). If you need to move across file system boundaries, or you
don't really know, the File::Copy module contains a move function,
which will do both.
> getting system messages from mv saying that FILE not found...when I KNOW
> and have confirmed that FILEA does exist. The problem I believe stems
> from my use of Arrays as arguments to the system() function (see below).
Well... If mv says the file doesn't exist, then it most likely
doesn't. I suspect that your confirmation procedure may be lsightly
less than absolutely accurate.
> I'm able to use the system() function with constants, but not with the
> array references.
nit: you're not using array references. In Perl a reference is a
special thingy. You probably mean array elements.
> @files=`ls $QUEUE/*`;
Hmmm.
This probably would have been better:
@files = glob("$QUEUE/*");
but this is probably the best way:
opendir(QUEUE, $QUEUE) || die "Cannot opendir $QUEUE:$!";
my @files = grep { ! /^\./ } readdir QUEUE;
closedir QUEUE;
Note that they are not all the same thing:
my @f1 = `ls $QUEUE/*`;
This will fill an array with a list of files, subdirectories and files
in subdirectories, as well as empty lines. Note that each line is
terminated with a newline, and that file names are a mix of complete
and incomplete file names. This is probably not what you want.
(complete: $QUEUE/filename. incomplete: filename)
(Each file directly in $QUEUE will be absolute. Each file in a
subdirectory of $QUEUE will be relative, this depends a bit on your
implementation of ls(1))
my @f2 = `ls $QUEUE`
This will fill @f2 with a mix of directory and file names relative to
$QUEUE (depending a bit on your implementation of ls(1)). Array
elements may contain whitespace, and are definitely terminated by a
newline.
my @f3 = glob "$QUEUE/*";
@f3 contains all file names and directory names as expanded by the
shell. Normally that means all of the ones not starting with '.'. Path
names are absolute.
my @files = grep { ! /^\./ } readdir QUEUE;
@files will contain the files in $QUEUE that do not start with a '.'
(directories are just files). file names are relative to $QUEUE. To
fix that:
my @files = map { "$QUEUE/$_" } grep { ! /^\./ } readdir QUEUE;
And if you also want to make sure you don't get directories:
my @files = map { "$QUEUE/$_" }
grep { ! /^\./ && ! -d "$QUEUE/$_" }
readdir QUEUE;
[snip of code]
Your code shows me that you didn't actually clean up the output of ls
before using it, meaning that your array elements contain whitespace
and newlines which are not part of the file name. That's where things
went wrong.
I would advise you to avoid using external programs, especially if
they're not very portable (like ls), and even more especially if you
have to post process the output to clean it up. Use as much of the
builtin functionality of perl as possible. The readdir is the best,
closely followed by glob, even though glob still does a call to an
external program.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: 26 Aug 1999 01:47:51 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Perl a Black Sheep?
Message-Id: <7q26c7$75k@dfw-ixnews12.ix.netcom.com>
Ala Qumsieh (aqumsieh@matrox.com) wrote:
: There is a problem with some of the "older" programmers. They learnt C
: (or some other useful language), and are comfortable with it although
: programming simple things with it (like opening files, and
: manipulating their contents) can be a real pain in the ass. They
I'd be willing to bet that a big part of the problem is that someone
who's learned how to jump through hoops and bang his head against the
wall in order to accomplish relatively simple tasks isn't going to be
very comfortable learning that there's a way to accomplish those tasks
with far less effort. It makes him feel like all his effort was worthless.
There's a possibly apocryphal story about a man who lost his sight in
childhood (but wasn't blind from birth) due to cataracts that weren't
treatable at the time. A surgical treatment became available by the time
he reached early middle age, and he had the operation, which successfully
restored his sight. Shortly afterwards, he became severely depressed,
and the doctors discovered that the reason was that all the work he had
been putting in to compensate for his blindness for most of his adult
life had become meaningless. It was all effort going in to accomplishing
tasks that he now found effortless. You'd think his reaction would have
been relief, but cognitive dissonance theory predicts the reaction he
actually had (he was from either the UK or the US; I'm not sure whether
he'd have had the same reaction if he came from a society that wasn't
influenced by the Puritan ethic).
Of course, this attitude is probably manifesting itself in something a
lot more concrete: the fear that if people learn to use Perl, they simply
won't need the "knowledge" imparted by his center's expensive courses.
------------------------------
Date: Thu, 26 Aug 1999 09:39:00 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Perl on NT vs Perl on Win98
Message-Id: <vA%w3.2$iM4.3319@vic.nntp.telstra.net>
Paul Alan Spitalny <paulsxxx@cascadelinear.com> wrote in message
news:37C47FD4.25FCA468@cascadelinear.com...
> Hi,
> I have written many perl scripts that I use in my Windows 95 operating
> system. One might be called "Fred.bat" I basically type in the name of
> the program in ( "fred") the "DOS prompt" window. My question to you
> folks out in Perl space is two fold:
>
> 1) Would I use the programs the same way if I was using Win98 or NT?
Pretty much exactly the same.
> 2) In which operating system would these scripts run faster; NT or Win98
Microsoft claim NT to do things faster, though it's generic 'dos
compatibility' is not as good.
I can't see this affecting Perl at all though... I use both and the only
major difference I've had to deal with
is the inability to perform file locking in 98. That may be something to
consider.
I would think things other than Perl would drive your decision between the
two OS.
> OOPS lied, I have three questions:
> 3) Is there a better and faster way to run these programs in Win95/Win98
> or NT?
Create a shortcut from the desktop with the association so you don't have to
go to the command prompt?
>
> These questions come up 'cause I'm considering getting a new computer
> and need to decide on Win98 or NT (Linux is not an option at this point
> for me)
>
> Thank you for your help.
>
> Paul
------------------------------
Date: Wed, 25 Aug 1999 18:25:10 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Regex Question
Message-Id: <MPG.122e374fafa5a32c989ea5@nntp.hpl.hp.com>
In article <1415c574.1e2f82e8@usw-ex0102-014.remarq.com> on Wed, 25 Aug
1999 16:02:04 -0700, Samay <samay1NOdzSPAM@hotmail.com> says...
> Hi, I am looking for some simple regex solution.
Why constrain the solution space? I'll deliberately show a solution
without a regex.
> I have some files which contain multiple lines instead of
> single lines for a single piece..
<Sample data reproduced below.>
> I want to have
>
> Start this is the ok End
> Start this is the ok2 End
>
> Thus I would like to remove all new lines between Start and
> End
I don't think you want to remove them, which would run words together.
An ugly way to do this is line-at-a-time, maintaining a flag to remember
the state. The clean way uses the input record separator, $/. See
perlvar for details.
#!/usr/local/bin/perl -w
use strict;
{
local $/ = "End\n\n";
while (<DATA>) {
tr/\n / /s;
print "$_\n";
}
}
__END__
Start this
is
the ok End
Start this is
the ok2
End
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 25 Aug 1999 19:07:15 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: REQ: tell-a-friend script
Message-Id: <slrn7s91b7.lhu.abigail@alexandra.delanet.com>
Robert Brody (rabrody@earthlink.net) wrote on MMCLXXXV September MCMXCIII
in <URL:news:7q1o5h$5v4$1@fir.prod.itd.earthlink.net>:
__ Hi. I've been looking in the many fine Perl cgi sites for a "tell-a-friend"
__ Perl cgi script(s) to put at my own site rather than link to a service. Of
__ the scripts I've found so far, they send you (the refer'er) to a seperate
__ page which is where they fill the referral info into a form, then when they
__ submit the form, they're taken back to the originating page (the page they
__ are referring to a friend). But I would like to have this input form on the
__ page itself that they're about to refer, rather than take them to a seperate
__ page to do it. I've seen many "services" that give you their html/form info
__ to put on your page, but I haven't as yet found a script that offers this
__ ability. As mentioned, I would like to run this from my own cgi-bin and not
__ link to a service.
__
__ If you know of something along these lines, please point me to it. Much
__ appreciated.
I'd suggesting picking up the phone and call your friend, because your
description of forms going to pages via referers and then coming back
completely lost me.
Abigail
--
Phones are modern enough for me.
Have you considered bio-degradable pigeon carriers?
-----------== 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, 25 Aug 1999 17:07:28 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Select Multiple Form Field via Perl into Oracle error
Message-Id: <37C4853F.8B788040@cisco.com>
[ Simmo wrote:
> my $sql = qq{ $SQL1 };
> my $sth=$dbh->prepare( $sql );
> $sth->execute();
A check you can do here is to print $sql before it is passed to prepare(). If
prepare() complains then hand over this query string ( without the enclosing
quotes if any ) to SQLplus and see what error it complains about.
--
------------------------------
Date: Wed, 25 Aug 1999 20:06:16 -0400
From: Ed Robisheaux <eroby@webpositioning.com>
Subject: Server Side Include Parameters
Message-Id: <250819992006168957%eroby@webpositioning.com>
Does anyone know the syntax for passing parameters from a web page to a
perl script when using the exec cmd with server side includes turned
on?
eroby@webpositioning.com
------------------------------
Date: 25 Aug 1999 19:10:52 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Sorting a list of lists
Message-Id: <slrn7s91i1.lhu.abigail@alexandra.delanet.com>
DJ (djten@sisna.com) wrote on MMCLXXXV September MCMXCIII in
<URL:news:37c3603e@news.sisna.com>:
FAQ
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
-----------== 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: Thu, 26 Aug 1999 00:44:41 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: The extent of double-quotish interpolation
Message-Id: <Z50x3.25010$x04.1484087@typ11.nn.bcandid.com>
In article <7q1ns6$7qf$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Alan Curry
><pacman@defiant.cqc.com>],
>who wrote in article <KKYw3.24595$x04.1456615@typ11.nn.bcandid.com>:
>> print "$i";
>> print "$a[0]";
>> print "@a";
>> print "$i+1";
>> print "$a[$i+1]";
>> print "$a[$i+1]+1";
>> print "$f->()+1";
>
>I would think that this one is the only one which might be
>hard-to-predict, all the rest is straightforward: arrays and scalars
>constructed using $, blocks, [], {}, ->[] and ->{} are interpolated if
>no whitespace between the tokens intervene.
Let me add a couple more fun ones:
my %h=(foo=>'bar', bar=>'baz');
my $s='foo';
print "$h{'foo'}";
print "$h{$s}";
print "$h{$h{$s}}";
print "$h{\"$h{$s}\"}";
Anybody else surprised by the last one?
>Note also that last week Larry raised the question of allowing
>interpolation of $subref->() in strings.
>
>Of course, backward-compatibility police intervened. ;-)
I'm trying to get at some clear, unambiguous documentation of what gets
interpolated and what doesn't. The starting points are easy to define. easy
to spot. It's either a $ or a @ followed by either an symbol name or a {.
But the ending point of an interpolation is really hard to pin down with such
a simple rule.
I guess I'm not really _surprised_ by most of those examples. It's just that
there seem to be a lot of unwritten rules at work here. In double quotes, if
$i is followed by [ then the [ is applied as a subscript operator. If $i is
followed by + then the + is not applied as an addition operator. If $i is
followed by -> then it may or may not be applied as a dereference operator
depending on whether the -> is followed by [, {, or (. (And what if it's
followed by a method name?)
perlop just says this:
For constructs that do interpolation, variables beginning
with "$" or "@" are interpolated
"$a[2..$f->()]" is not just a "variable beginning with $ or @". It's a
complex expression (involving a function call!). Being inside brackets must
give it special status. But perlop doesn't say anything about that. I want to
know exactly how the interpreter decides where to stop interpolating. A
regexp that takes a string like q{$a[2..$f->()]junk} and returns the portion
before the "junk" would be ideal :)
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: Wed, 25 Aug 1999 17:35:51 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: VERY VERY VERY weird things happening
Message-Id: <MPG.122e2bc3258c1c6e9896d2@nntp1.ba.best.com>
Slav Inger (vinger@mail.ford.com) seems to say...
> %hash = (
> h1 => {}
> );
>
> I reference the hash values in the following way:
> $hash{h1}->[0], $hash{h1}->[1], and so on.
Hash of hashes or hash or arrays?
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: 25 Aug 1999 19:14:24 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: What are valid characters in hash keys
Message-Id: <slrn7s91ok.lhu.abigail@alexandra.delanet.com>
Mark McCoy (mcking@cajunbro.com) wrote on MMCLXXXV September MCMXCIII in
<URL:news:37C45794.C2AC828A@cajunbro.com>:
!! Larry Rosler wrote:
(For some reason, Larry's postings don't arrive at my news server anymore.
What did HP do to piss newsfeeds off?)
!! You are _technically_ correct, but I doubt anyone would really want to use ''
!! '$_', '@foo', '()', etc... as hash keys! I would like to see _you_ write a
!! fairly detailed (i.e. lengthy) script that uses keys such as these!
Is that a challenge?
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");
-----------== 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: 25 Aug 1999 23:37:26 GMT
From: regan@ao.com (Dave Regan)
Subject: Re: What are valid characters in hash keys
Message-Id: <7q1unm$be1$1@bashir.peak.org>
In article <37C45794.C2AC828A@cajunbro.com>,
Mark McCoy <mcking@cajunbro.com> writes:
> Larry Rosler wrote:
>>
>> In article <37BDC174.E4E3132F@cajunbro.com> on Fri, 20 Aug 1999 20:58:28
>> +0000, Mark McCoy <mcking@cajunbro.com> says...
>> > Roger Musson wrote:
>> > >
>> > > $hash{key}='some_value';
>> > >
>> > > What are the valid characters for 'key'
>> > >
>> > > I can't find any reference to this anywhere, all examples use
>> > > alphanumeric.
>> ...
>> > I believe it is the same as for the variable names themselves, no
>> > "@$%[]{}<>()..." (unless you want to spend the whole time escaping the reserved
>> > characters)
>>
>> There are no reserved characters.
>>
>> > Stick with alphanumeric and you will be ok.
>>
>> Yes, you will, but you are totally wrong about this. Absolutely any
>> string will do, including even the null string "".
> You are _technically_ correct, but I doubt anyone would really want to use '',
> '$_', '@foo', '()', etc... as hash keys! I would like to see _you_ write a
> fairly detailed (i.e. lengthy) script that uses keys such as these!
But the real issue is for keys which come in from user supplied data.
If you had to filter out "bad characters" from keys, the program you
write may well be unreliable if you don't filter them all out. If
the rule allows for *any* key, then the programming is trivial: simply
use the user data as the key. And this is the rule that Perl choose.
I agree that nobody (sane) would use '$_' as an explicit key within
a program. However, it may very well show up in data.
Dave Regan
regan@ao.com
------------------------------
Date: Wed, 25 Aug 1999 17:51:31 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: What are valid characters in hash keys
Message-Id: <MPG.122e2f6ec9c5e020989ea2@nntp.hpl.hp.com>
[Posted and a courtesy copy sent, just in case. :-]
In article <slrn7s91ok.lhu.abigail@alexandra.delanet.com> on 25 Aug 1999
19:14:24 -0500, Abigail <abigail@delanet.com> says...
> Mark McCoy (mcking@cajunbro.com) wrote on MMCLXXXV September MCMXCIII in
> <URL:news:37C45794.C2AC828A@cajunbro.com>:
> !! Larry Rosler wrote:
>
> (For some reason, Larry's postings don't arrive at my news server anymore.
> What did HP do to piss newsfeeds off?)
I've been making it to deja.com, though this last one hasn't got there
yet. My responses below are copied unedited from that posting. I can't
see a good reason to respond to the challenge.
> !! You are _technically_ correct, but I doubt anyone would really want to use ''
> !! '$_', '@foo', '()', etc... as hash keys! I would like to see _you_ write a
> !! fairly detailed (i.e. lengthy) script that uses keys such as these!
Hmmm. To me '_technically_ correct' eq 'correct'. Does anyone see it
any differently?
> Is that a challenge?
As for the challenge, I write programs. I don't know what 'scripts'
might be.
I could throw together a Perl expression evaluator that is implemented
via a subroutine dispatch-table driven by a hash whose keys are the
operator tokens ('+', '-', '*', '/', '%') or groupers ('(', ')'). But
that would be pretty boring, because it has been published already in
various books, implemented in C using a switch on the tokens. So I
won't bother. You should be able to get the idea from that description.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 25 Aug 1999 16:52:19 -0700
From: moseley@best.com (Bill Moseley)
Subject: YAREQ (yet another regexp question)
Message-Id: <MPG.122e218b1e240dd69896d1@nntp1.ba.best.com>
I get passed a list of words, and a list of end characters to remove.
But I want to leave on any '*'.
my @words = qw/
hello
howdy+
jambo*
later]*
bye-bye-*
/;
I'd like to see them end up like:
hello
howdy
jambo*
later*
bye-bye*
$end_chars = '+-]'; # chars to remove at end of words
I was trying something like:
s/[quotemeta($end_chars)](?=\**)$//;
find the end char (with or without an '*' at the end) and replace it
with nothing.
I've go two problems.
1) The regexp doesn't work. Here I'm stuck.
2) $end_chars might have a ']' in the first location.
Say:
$endchars = ']+-';
so
s/[quotemeta($endchars)]// looks like
s/[\]\+\-]// which is [\] plus some other chars.
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: Wed, 25 Aug 1999 17:50:06 -0700
From: moseley@best.com (Bill Moseley)
Subject: YAREQ (yet another regexp question)
Message-Id: <MPG.122e2f1c25e526229896d4@nntp1.ba.best.com>
[sorry if reposted -- my news server seem to have eaten the first copy]
I'm passed a list of words, and a scalar string of end characters to
remove. I want to leave on any '*'.
my @words = qw/
hello
howdy+
jambo*
later]*
bye-bye-*
/;
I'd like to see them end up like:
hello
howdy
jambo*
later*
bye-bye*
$end_chars = '+-]'; # chars to remove at end of words
I was trying something like:
s/[quotemeta($end_chars)](?=\**)$//;
find the end char (with or without an '*' at the end) and replace it
with nothing.
I've go two problems.
1) The regexp doesn't work. Here I'm stuck.
2) $end_chars might have a ']' in the first location.
Say:
$endchars = ']+-';
so
s/[quotemeta($endchars)]// looks like
s/[\]\+\-]// which is [\] plus some other chars.
Thanks,
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: Wed, 25 Aug 1999 18:45:42 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: YAREQ (yet another regexp question)
Message-Id: <MPG.122e3c202f6cc7f9989ea6@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <MPG.122e2f1c25e526229896d4@nntp1.ba.best.com> on Wed, 25 Aug
1999 17:50:06 -0700, Bill Moseley <moseley@best.com> says...
...
> $end_chars = '+-]'; # chars to remove at end of words
>
> I was trying something like:
>
> s/[quotemeta($end_chars)](?=\**)$//;
>
> find the end char (with or without an '*' at the end) and replace it
> with nothing.
>
> I've go two problems.
>
> 1) The regexp doesn't work. Here I'm stuck.
>
> 2) $end_chars might have a ']' in the first location.
Expressions aren't evaluated within character classes! Do the quotemeta
outside the regex.
my $qchars = quotemeta $end_chars;
s/[$qchars](?=\**$)//; # With an /o if $end_chars doesn't change.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
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 646
*************************************