[19098] in Perl-Users-Digest
Perl-Users Digest, Issue: 1293 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 12 14:10:37 2001
Date: Thu, 12 Jul 2001 11:10:16 -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: <994961416-v10-i1293@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 12 Jul 2001 Volume: 10 Number: 1293
Today's topics:
Re: rand confusion <peb@bms.umist.ac.uk>
Recommendations for a 2nd book on Perl (JR)
Re: Recommendations for a 2nd book on Perl (dave)
Re: Recommendations for a 2nd book on Perl <gnarinn@hotmail.com>
Re: Removing tags from an HTML file. (mc)
sendmail based on a state <nope@nospam.com>
Re: sendmail based on a state <andras@mortgagestats.com>
Re: sendmail based on a state <rsherman@ce.gatech.edu>
Re: sendmail based on a state (Eric Bohlman)
Re: Socket programming problem <leed@ucdavis.edu>
Re: sortlen -- filter to sort text by line length <ren@tivoli.com>
Re: Text variable containing '$' (Tad McClellan)
Using a variable in a regular expression (Pete)
Re: Where is MD5 (Otto Wyss)
Re: Where is MD5 <gnarinn@hotmail.com>
Wildcards in hash (associative) arrays? <bholness@nortelnetworks.com>
Re: Wildcards in hash (associative) arrays? (Damian Conway)
Re: Wildcards in hash (associative) arrays? <gnarinn@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 12 Jul 2001 15:20:08 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: rand confusion
Message-Id: <3B4DB218.7E5FA3D1@bms.umist.ac.uk>
Philip Lees wrote:
<snip>
> Thank you, but I already understood that rand was expecting an
> argument. What I didn't understand was how the <> operator could be an
> argument for rand? According to the docs the argument should be a
> positive number.
#!/usr/bin/perl -w
for(0..10){
print rand <DATA>, "\n";
}
__DATA__
1
90
4
900
34
7000
RESULTS:-
0.390394578063027
51.9291613192692
2.47849575631749
503.470404038172
17.9698715989332
5750.00361925039
So you see, you can read in the positive number from a filehandle.
HTH
Paul
------------------------------
Date: 12 Jul 2001 07:47:25 -0700
From: tommyumuc@aol.com (JR)
Subject: Recommendations for a 2nd book on Perl
Message-Id: <319333f5.0107120647.42e8c42e@posting.google.com>
I would appreciate any suggestions anyone may have for a second book
on Perl. The first book through which I have gone is "Sams-Teach
Yourself Perl in 24 Hours" (how ridiculous is that?). I use the
"Programming Perl" and "CGI/Perl Cookbook" as reference books, but I
really need a good second "how-to" book on Perl. I have used Perl to
create an intranet database for a recent office project, but this
database only contained 317 relatively small records. The next
database that I am required to create will contain over 30,000 records
(small records again). The second Perl book for which I am asking
suggestions should cover well hashes, databases (especially) and CGI
(I won't be able to use DBI, because the intranet database must be put
on an intranet production server and I've read many times that DBI
shouldn't be used for production--so that may be out, but I have
confidence somebody out there has a good idea how to handle large
intranet databases without DBI).
Thank you very much!
Joe
------------------------------
Date: 12 Jul 2001 09:09:04 -0700
From: usted@cyberspace.org (dave)
Subject: Re: Recommendations for a 2nd book on Perl
Message-Id: <e2c00ae.0107120809.16c877f4@posting.google.com>
> (I won't be able to use DBI, because the intranet database must be put
> on an intranet production server and I've read many times that DBI
> shouldn't be used for production--so that may be out, but I have
> confidence somebody out there has a good idea how to handle large
> intranet databases without DBI).
DBI shouldn't be used for production? Really? What are the reasons
behind this?
I would recommend reading Programming the Perl DBI by Oreilly (strange
that they devoted a whole book on a toy), actually reading every page
of Programming Perl, Learning Perl, and the Perl Cookbook. They are
all really good books, written in most cases by the people who have
developed what they are describing.
dave
------------------------------
Date: Thu, 12 Jul 2001 16:23:33 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Recommendations for a 2nd book on Perl
Message-Id: <994955013.394353818148375.gnarinn@hotmail.com>
In article <319333f5.0107120647.42e8c42e@posting.google.com>,
JR <tommyumuc@aol.com> wrote:
> I've read many times that DBI
>shouldn't be used for production--so that may be out
this is nonsense.
what database are you using?
gnari
------------------------------
Date: Thu, 12 Jul 2001 13:58:11 GMT
From: nospam@home.com (mc)
Subject: Re: Removing tags from an HTML file.
Message-Id: <3b4dacaa.34094249@news>
On Tue, 10 Jul 2001 10:59:12 +0200, "scotth"
<scott@remove.generator.co.za> wrote:
>Hi All.
>Could anyone out there please advise me on how to remove all markup and
>scripting from an HTML file
>I want to remove all HTML tags, JavaScript, embedded PHP code etc, and only
>have the meaningful content left.
>My PERL knowledge is very limited, but am I correct in assuming that it
>would involve using the s/ operator?
>I have had a look around on the web, and I could only find this
>$_=~s/<\?([^>])*\?>/ /gs;
>which seems to work great for HTML tags, but I am still left with
><script><!-- --></script> and <? ?> and everything in between.
>All advice is welcomed!
>Thanks in advance.
>--
>Scott Houseman
>Software Developer/Systems Administrator
>
>tel +27 21 425 9710
>fax +27 21 425 9713
>
>GENERATOR COMMUNICATIONS | BE AN ISLAND
Easiest way is:
% lynx -dump URL
Assuming you're on a *NIX system and have lynx available...
mc
------------------------------
Date: Thu, 12 Jul 2001 09:18:52 -0500
From: "Grover Thomas" <nope@nospam.com>
Subject: sendmail based on a state
Message-Id: <9ikblo$4lf$1@slb0.atl.mindspring.net>
Forgive the easy question, but I'm new to perl and trying to modify an
existing script.
I have a form with various fields on it, one of them being a US State or
Region. What I would like to do is send and email to the appropriate
representative for that State or Region based on the value in the form
field. For example, if a user selected "Arizona" from the drop down box, I
want to send an email to the representative for Arizona containing all the
information in the other form fields.
Can someone show me a code sample of how to do this in Perl? I know how to
do it in other languages, but Perl syntax has me stumped.
Thanks.
------------------------------
Date: Thu, 12 Jul 2001 11:15:09 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: sendmail based on a state
Message-Id: <3B4DBEFD.596C34B2@mortgagestats.com>
Grover Thomas wrote:
> Forgive the easy question, but I'm new to perl and trying to modify an
> existing script.
>
> I have a form with various fields on it, one of them being a US State or
> Region. What I would like to do is send and email to the appropriate
> representative for that State or Region based on the value in the form
> field. For example, if a user selected "Arizona" from the drop down box, I
> want to send an email to the representative for Arizona containing all the
> information in the other form fields.
>
> Can someone show me a code sample of how to do this in Perl? I know how to
> do it in other languages, but Perl syntax has me stumped.
>
> Thanks.
Probably the best way is to use a hash to associate the states/regions with the
reps' e-mail addresses, sort of like this
%reps={'Arizona' => 'joe.schmoe@arizonaisp.com',
'Michigan' => 'bill@me.com',
'Northeast' => 'jeff_waters@yankee.net'};
Then you can just do $reps{'Arizona'} to pull up the Arizona rep's e-mail.
To see how you can read the form input, read the documentation to CGI.pm. To
see how you can send mail, read the FAQ titled "How can I send mail?" You might
be able to get more help in a CGI-related newsgroup.
------------------------------
Date: Thu, 12 Jul 2001 11:21:21 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: sendmail based on a state
Message-Id: <3B4D41E1.B9FD78DC@ce.gatech.edu>
Grover Thomas wrote:
>
> Forgive the easy question, but I'm new to perl and trying to modify an
> existing script.
>
> I have a form with various fields on it, one of them being a US State or
> Region. What I would like to do is send and email to the appropriate
> representative for that State or Region based on the value in the form
> field. For example, if a user selected "Arizona" from the drop down box, I
> want to send an email to the representative for Arizona containing all the
> information in the other form fields.
>
> Can someone show me a code sample of how to do this in Perl? I know how to
> do it in other languages, but Perl syntax has me stumped.
>
> Thanks.
perldoc CGI
------------------------------
Date: 12 Jul 2001 17:15:58 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: sendmail based on a state
Message-Id: <9ikm0e$psd$2@bob.news.rcn.net>
Andras Malatinszky <andras@mortgagestats.com> wrote:
> Probably the best way is to use a hash to associate the states/regions with the
> reps' e-mail addresses, sort of like this
> %reps={'Arizona' => 'joe.schmoe@arizonaisp.com',
> 'Michigan' => 'bill@me.com',
> 'Northeast' => 'jeff_waters@yankee.net'};
Not with those curly braces, though. You use curly braces when assigning
to a hash *reference*; you use parentheses when assigning to a *hash*. If
warnings are enabled, your code will generate a complaint about assigning
an odd number of elements to a hash.
------------------------------
Date: Thu, 12 Jul 2001 10:19:51 -0700
From: "Dustin Lee" <leed@ucdavis.edu>
Subject: Re: Socket programming problem
Message-Id: <9ikm0a$aa$1@woodrow.ucdavis.edu>
Thanks for looking at the code....
"James Richardson" <time4tea@monmouth.com> wrote in message
news:9ij954$p1c$1@slb1.atl.mindspring.net...
>
> "Dustin Lee" <leed@ucdavis.edu> wrote in message
> news:9iigk6$b7b$1@woodrow.ucdavis.edu...
>
> [pretty yuk code]
sorry if it caused you pain.......
>
> Flicking quickly through your code, your appear to think that a write of n
> bytes will always succeed in one go, which is absolutely not the case.
>
> In pseudo [aka i hope i didnt forget anything] code it should look
something
> like
>
> my $request = "blah"
>
> while ( length ( $request ) ) {
> my $sent = $socket->syswrite ( $request, 8192 );
> if ( $!{EAGAIN} ) {
> $sent ||= 0;
> }
> elsif ( ! defined ( $sent ) ) {
> return disconnect_client ( $socket );
> }
>
> if ( $sent ) {
> $request = substr ( $request , $sent );
> }
> }
>
> That is, loop around sending bits n bobs until you sent the whole request.
>
> Receiving is the same.
I've added the check for the completion of the write and already had checks
for reading the responses, but this doesn't seem to be my problem. None of
the writes I'm doing ever seem to have problems finishing in one pass, but
at least now I check for this possiblity. I suspect the real problem may be
how different IP stacks work (or the servers are just broken). My main
problem seems to come down to the fact that I seem to loose the connection
to the server if the request is over a certain size and it's sent through
the network. Sending large requests to "localhost" doesn't seem to be a
problem. The servers are all "major" industrial strength servers (IIS,
Apache, Netscape and the like). It may just be that some of the servers are
"broken" and I just have to deal with it, but it seems strange to me that
they get different results at different times (e.g. sometimes several
requests in a row work, sometimes only one or none.)
Any ideas why this might be?
Any tricks I should consider for "being more gentle" to the server so as to
not compell it to disconnect?
thanks again for your help,
dustin
>
> Its more difficult if you have multiple connections.
>
> HTH
>
> James
>
>
------------------------------
Date: 12 Jul 2001 11:38:56 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: sortlen -- filter to sort text by line length
Message-Id: <m3bsmqw19b.fsf@dhcp9-161.support.tivoli.com>
On 12 Jul 2001, demerphq@hotmail.com wrote:
> Benjamin Goldberg <goldbb2@earthlink.net> wrote in message
> news:<3B49CB78.BD415164@earthlink.net>...
>
>> Or combine things even further:
>> print sort { length($a) <=> length($b) } <>;
>> or, with GRT:
>> print map { substr $_, 4 } sort map { pack 'Na*', length, $_ }
>> <>;
>
> Curious about something, surely the following is more efficient
> (focusing only on the sort part, input/output concerns aside....)
>
> #Shwarzian Transform
> my @sorted=map {
> $_->[1]
> } sort {
> $a->[0] <=> $b->[0]
> } map {
> [length($_),$_]
> } @string_list;
[snip]
> Obviously this is basically the same as your last example with no
> substr overhead.
Except that it misses the big win of GRT over ST: the default compare
operation is *much* faster.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 12 Jul 2001 08:59:55 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Text variable containing '$'
Message-Id: <slrn9kr7qb.idu.tadmc@tadmc26.august.net>
JJ <jocke30_gbg@hotmail.com> wrote:
>"Michael Carman" <mjcarman@home.com> wrote in message
>news:3B4C759E.57BFA7FC@home.com...
>> JJ wrote:
>> >
>> > I collect table names from a database and stores them in a array.
>> > The table names can contain the character '$' such as 'My$Table'.
>> > Before I store the value in the array I need to determine if it
>> > contains the character and replace '$' with '\$'.
>>
>> Hmm. Why do you think you need to do this? I highly doubt that it's
>> necessary.
>
>I have a Perl program that calls another perl program via system(...) with
>an parameter value, such as:
>
>system('./myOtherPerlApp.pl $param1');
^ ^
^ ^
>$param1 contains the value 'test$again'.
It does not matter what $param1 contains, myOtherPerlApp.pl cannot
see its contents. Did you intend to use double quotes there instead?
>When myOtherPerlApp.pl get this value it only uses 'test' since it handles
>'$again' as a uninitilized variable.
It cannot see 'test' nor '$again' *at all*.
You still have not shown why you think you need to escape the
dollar signs at all. I highly doubt that it's necessary.
Please try again to explain why you think it is necessary to
escape the dollar sign before assigning it to an array element.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 12 Jul 2001 17:38:02 GMT
From: Peter@angeltec.fsnetNOTTHIS.co.uk (Pete)
Subject: Using a variable in a regular expression
Message-Id: <3b4dde5b.289465678@news.btinternet.com>
Hi,
I think I'm close with this but obviously not close enough!!
This works :
if($psk =~ m"(\d\d[A-Z][A-Z]\d\d\d\d)")
# 12AB3456 passes
I'm trying to use a variable to represent the matching string:
$pskformat = "m\"\(\\d\\d[A-Z][A-Z]\\d\\d\\d\\d\)\""
This produces m"(\d\d[A-Z][A-Z]\d\d\d\d)" when I print it out but:
if($psk =~ $pskformat)
# never passes
Any thoughts please
Pete
------------------------------
Date: Thu, 12 Jul 2001 17:32:04 +0200
From: otto.wyss@bluewin.ch (Otto Wyss)
Subject: Re: Where is MD5
Message-Id: <1ewg0ew.11hahz21jzdvegN%otto.wyss@bluewin.ch>
> >try locate MD5.pm
> >
> >my guess is that you might find it under /usr/lib, but your 5.6.1
> >perl uses libraries in /usr/local/lib
> >
> >it is probably best to reinstall the module.
>
> ..and while you're at it, install Digest::MD5 instead. The current MD5
> module is just a wrapper around Digest::MD5.
>
> The next stable relese of perl will have Digest::MD5 as part of the
> standard distribution.
Yes Digest::MD5 is working nicely. Anyway why does
perldoc MD5
perldoc -f MD5
perldoc -q MD5
show no results results instead giving hints to look under Digest::MD5?
Why isn't there a
perldoc *MD5*
perldoc *
to show any related modules? How can I see what modules are currently
installed?
O. Wyss
------------------------------
Date: Thu, 12 Jul 2001 16:12:00 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Where is MD5
Message-Id: <994954320.142553756944835.gnarinn@hotmail.com>
In article <1ewg0ew.11hahz21jzdvegN%otto.wyss@bluewin.ch>,
Otto Wyss <otto.wyss@bluewin.ch> wrote:
>>
>> The next stable relese of perl will have Digest::MD5 as part of the
>> standard distribution.
>
comment: when quoting, it is nice to leave in the attribution, so that
we can see who said what.
>Yes Digest::MD5 is working nicely. Anyway why does
>
>perldoc MD5
actually , on my system this says (among other things):
The MD5 module is depreciated. Use Digest::MD5 instead.
The current MD5 module is just a wrapper around the Digest::MD5
module. It is provided so that legacy code that rely on the old
interface still work and get the speed benefit of the new module.
I guess you have not installed it.
perldoc <module> can only extract documentation from modules that
are present (have been installed)
>perldoc -f MD5
perldoc -f is for built-in functions. MD5 is not one of these.
>perldoc -q MD5
I guess there is no frequently asked question about MD5
>
>show no results results instead giving hints to look under Digest::MD5?
>Why isn't there a
>
>perldoc *MD5*
personally, i often use lthe command locate for this purpose.
for example: locate MD5.pm
on your system you may have something different, but most have
some way of searching for files
>perldoc *
>
>to show any related modules? How can I see what modules are currently
>installed?
perldoc perllocal
gnari
------------------------------
Date: Thu, 12 Jul 2001 17:08:48 +0100
From: "Ben Holness" <bholness@nortelnetworks.com>
Subject: Wildcards in hash (associative) arrays?
Message-Id: <9iki7t$5jo$1@qnsgh006.europe.nortel.com>
Hi all,
I have a hash array that is indexed by a number of keys, using "<:::>" as a
separator. For the purposes of this post, the array contains information
about dogs. In order to uniquely identify a dog (and to be able to access
and sort the array quickly), each entry in the array has a sort string, the
dogs name and the owners name. The judges marks are contained in the value
part of the array.
So I could end up with:
$dogs{"sortKey<:::>Fido<:::>John"}="7,6,6,5";
$dogs{"sortKey<:::>Rover<:::>Jane"}="3,5,2,5";
$dogs{"sortKey<:::>Patsy<:::>Fred"}="7,6,2,4";
$dogs{"sortKey<:::>Spot<:::>Charles"}="2,6,7,5";
$dogs{"sortKey<:::>Digger<:::>Ann"}="4,5,6,7";
The sortKey could be anything - it could be the dogs name, the score for
grooming, the colour etc. This allows me to sort the array for output with a
simple "sort keys".
However, I would like to be able to access a specific part of the array
without knowing the sortKey, so I could say:
Find the key/value pair in %dogs, where the key is "*<:::>Spot<:::>Charles",
so that it wouldn't matter what the sortKey is.
Obviously I can do this by looking at each item in the array, but that seems
rather longwinded to me. Is there any way to wildcard a key, or to pattern
match a key (something like $dogs{/Spot<:::>Charles/}) in perl?
Cheers,
Ben
------------------------------
Date: 12 Jul 2001 16:39:16 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Wildcards in hash (associative) arrays?
Message-Id: <9ikjrk$5a8$1@towncrier.cc.monash.edu.au>
"Ben Holness" <bholness@nortelnetworks.com> writes:
> Is there any way to wildcard a key, or to pattern
> match a key (something like $dogs{/Spot<:::>Charles/}) in perl?
@matches = @dogs{grep /Spot<:::>Charles/ keys %dogs}
Damian
------------------------------
Date: Thu, 12 Jul 2001 16:21:06 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Wildcards in hash (associative) arrays?
Message-Id: <994954866.59785697190091.gnarinn@hotmail.com>
In article <9iki7t$5jo$1@qnsgh006.europe.nortel.com>,
Ben Holness <bholness@nortelnetworks.com> wrote:
>
>I have a hash array that is indexed by a number of keys, using "<:::>" as a
>separator. For the purposes of this post, the array contains information
>about dogs. In order to uniquely identify a dog (and to be able to access
>and sort the array quickly), each entry in the array has a sort string, the
>dogs name and the owners name. The judges marks are contained in the value
>part of the array.
>
>So I could end up with:
>
>$dogs{"sortKey<:::>Fido<:::>John"}="7,6,6,5";
>$dogs{"sortKey<:::>Rover<:::>Jane"}="3,5,2,5";
>$dogs{"sortKey<:::>Patsy<:::>Fred"}="7,6,2,4";
>$dogs{"sortKey<:::>Spot<:::>Charles"}="2,6,7,5";
>$dogs{"sortKey<:::>Digger<:::>Ann"}="4,5,6,7";
>
if the sortkey is only used for sorting, and the name/owner is enough
to uniquely identify a dog, i suggest you keep that out of the hash, and
put it into a separate one
gnari
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1293
***************************************