[18619] in Perl-Users-Digest
Perl-Users Digest, Issue: 787 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 28 03:05:37 2001
Date: Sat, 28 Apr 2001 00:05:07 -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: <988441507-v10-i787@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 28 Apr 2001 Volume: 10 Number: 787
Today's topics:
Re: "return" from a "require"? <xris@dont.send.spam>
Re: "return" from a "require"? (Abigail)
Re: "return" from a "require"? (Logan Shaw)
Re: $?=32512 Translation please <bwalton@rochester.rr.com>
Re: $?=32512 Translation please <ren@tivoli.com>
Re: Appending to files and flock. (Tad McClellan)
Re: Appending to files and flock. (Gwyn Judd)
Re: Benchmark.pm is REALLY inaccurate? (Abigail)
Re: extracting hostname from a url? (Abigail)
Re: Finding all elements in an array matching a certian (Tad McClellan)
Re: First and last element in list loop <ren@tivoli.com>
Re: First and last element in list loop (Anno Siegel)
Re: First and last element in list loop <uri@sysarch.com>
Re: First and last element in list loop (Gwyn Judd)
Re: How to down size /usr/bin/perl ? michal@gortel.phys.ualberta.ca
Re: Must send lots of emails <webmaster@webdragon.unmunge.net>
Re: Regular expression for zip code <sharding@ccbill.com>
Re: Regular expression for zip code <xris@dont.send.spam>
Re: Storing the CGI object in my module? <bwalton@rochester.rr.com>
Re: Strange string -> num conversion <ren@tivoli.com>
Re: Strange string -> num conversion (Abigail)
Re: Strange string -> num conversion <sharding@ccbill.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 27 Apr 2001 20:09:58 -0500
From: xris <xris@dont.send.spam>
Subject: Re: "return" from a "require"?
Message-Id: <xris-10CD0E.20095827042001@news.evergo.net>
In article <j43ketg748sgut87635v617r7kkh3vgj5s@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
> I would have doubts myself, because it most definitely doesn't work in
> the main script, so I don't trust it in a required file either.
> I try to do this instead:
> if(COND) {
> ...
> } else {
> ...
> }
yup, that's what I do... guess it's technically "cleaner," anyway....
Thanks.
------------------------------
Date: Sat, 28 Apr 2001 01:29:50 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: "return" from a "require"?
Message-Id: <slrn9ek78e.mm6.abigail@tsathoggua.rlyeh.net>
xris (xris@dont.send.spam) wrote on MMDCCXCVI September MCMXCIII in
<URL:news:xris-D8DCAC.16092827042001@news.evergo.net>:
&& Is there any way to return early from a "require" - like return() allows
&& you to from a subroutine?
BEGIN {die}
HTH. HAND.
Abigail
--
BEGIN {$^H {join "" => ("a" .. "z") [8, 13, 19, 4, 6, 4, 17]} = sub
{["", "Just ", "another ", "Perl ", "Hacker\n"] -> [shift]};
$^H = hex join "" => reverse map {int ($_ / 2)} 0 .. 4}
print 1, 2, 3, 4;
------------------------------
Date: 27 Apr 2001 23:38:53 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: "return" from a "require"?
Message-Id: <9cdhgt$lb3$1@charity.cs.utexas.edu>
In article <j43ketg748sgut87635v617r7kkh3vgj5s@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>>> What you do is you return() from the file.
>I would have doubts myself, because it most definitely doesn't work in
>the main script, so I don't trust it in a required file either.
Returning from the main file is a different case than returning from a
"require"d file.
Anyway, the documentation says you can do it. "perldoc -f return"
says this:
return Returns from a subroutine, `eval', or `do FILE' with
the value given in EXPR.
and "perldoc -f require" says this:
The file is
included via the do-FILE mechanism, which is
essentially just a variety of `eval'.
So, it should be supported, if I'm putting those two together right.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Sat, 28 Apr 2001 01:22:11 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: $?=32512 Translation please
Message-Id: <3AEA1BAA.CC1D69B4@rochester.rr.com>
Stuart Moore wrote:
>
> A program I am trying to run in ``s in perl on FreeBSD is not working, and
> returns $?=32512. Is there any way to decode this to find out exactly what the
> error is?
Yes. That's 0x7f00, which means you got error 7f from the program you
tried to run inside the ``'s, that it didn't die from a SIG, and that
there wasn't a core dump. See perldoc perlvar, search for $?. You'll
have to look up the error codes for your program yourself (you didn't
say what program it was).
> Stuart
--
Bob Walton
------------------------------
Date: 27 Apr 2001 20:11:41 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: $?=32512 Translation please
Message-Id: <m3bsphhlpu.fsf@dhcp9-172.support.tivoli.com>
On Sat, 28 Apr 2001, stumo@bigfoot.com wrote:
> A program I am trying to run in ``s in perl on FreeBSD is not
> working, and returns $?=32512. Is there any way to decode this to
> find out exactly what the error is?
You usually want $?>>8, which in this case is 127. I'm not sure
exactly how you should know to recognize this as -1. (Though that
particular problem is *way* more wide-spread than just in Perl.)
Take a look at the description of $? (a.k.a. $CHILD_ERROR) in
perlvar(1) for more detail.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 27 Apr 2001 20:22:36 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Appending to files and flock.
Message-Id: <slrn9ek3ac.4tk.tadmc@tadmc26.august.net>
Paul the Nomad <taka@yarn.demon.co.uk> wrote:
>This thread is really appalling.
I agree. And I know who to blame and have taken the appropriate action.
>When I originally asked this, I was
>referred rudely
Since you do not quote what it is that you are referring to, we
are forced to guess. I can't see any rudeness, but perhaps you
see some rudeness in this reply:
----------------
No, it's something about the open mode.
Did you study perlopentut?
----------------
Is that the rude reply that you are referring to?
What is rude there? Looks fine to me.
>Before telling people to RTFM, might it not be preferable to ensure
>that the FM has the information requested?
Before starting yet another "file locking on this and that OS"
thread, might it not be preferable to ensure that the whole
thing has not already been played out multiple times already?
>If not, it would be better
>to STFU.
Golly, you insist on those last few scorepoints reserved for only
the most vile. OK, you got them!
>So far the totally inadequate answer
If Usenet does not get you the answer, then you need to look elsewhere.
This isn't a help desk.
We have no obligation to solve your problem.
You ask and then you take your chances with whatever responses you get.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 28 Apr 2001 05:51:52 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Appending to files and flock.
Message-Id: <slrn9ekmjm.978.tjla@thislove.dyndns.org>
"mein Luftkissenfahrzeug ist voll von den Aalen"
said Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) in
<9cd08b$qtc$2@mamenchi.zrz.TU-Berlin.DE>:
>According to Gwyn Judd <tjla@guvfybir.qlaqaf.bet>:
>> "mein Luftkissenfahrzeug ist voll von den Aalen"
>> said nobull@mail.com (nobull@mail.com) in
>> <u9u23af6ps.fsf@wcl-l.bham.ac.uk>:
>>
>> >OK here's the truth.
>>
>> <snip really good answer>
>>
>> That's excellent. I think this should go into the faq.
>
>Seconded.
Well, here is a patch. I'm not really sure how best to submit it. Should
I just post it to p5p with the word "[PATCH]" in the subject?
--- pod/perlfaq5.pod.old Sat Apr 28 11:03:44 2001
+++ pod/perlfaq5.pod Sat Apr 28 17:44:10 2001
@@ -723,6 +723,34 @@
If the count doesn't impress your friends, then the code might. :-)
+=head2 All I want to do is append a small amount of text to the end of a
+file. Do I *still* have to use locking?
+
+If you are on a system that correctly implements flock() and you use
+the example appending code from "perldoc -f flock" everything will be
+OK even if the OS you are on doesn't implement append mode correctly.
+So if you are happy to restrict yourself to OSs that implement flock()
+(and that's not really much of a restriction) then that is what you
+should do.
+
+If you know you are only going to use a system that does correctly
+implement appending (i.e. not Win32) then you can omit the seek() from
+the above code.
+
+If you know are only writing code to run on an OS and filesystem that
+does implement append mode correctly (a local filesystem on a modern
+Unix for example), and you keep the file in block-buffered mode and
+you write less than one buffer-full of output between each manual
+flushing of the buffer then each bufferload is almost garanteed to be
+written to the end of the file in one chunk without getting
+intermingled with anyone else's output.
+
+There is still a small theoretical chance that a signal will interrupt
+the system level write() operation before completion. There is also a
+possibility that some STDIO implementations may call multiple system
+level write()s even if the buffer was empty to start. There may be some
+systems where this probability is reduced to zero.
+
=head2 How do I randomly update a binary file?
If you're just trying to patch a binary, in many cases something as
--- pod/perlfaq.pod.old Sat Apr 28 17:45:02 2001
+++ pod/perlfaq.pod Sat Apr 28 17:48:54 2001
@@ -692,6 +692,11 @@
=item *
+All I want to do is append a small amount of text to the end of a
+file. Do I *still* have to use locking?
+
+=item *
+
How do I randomly update a binary file?
=item *
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
INJURY
n. An offense next in degree of enormity to a slight.
------------------------------
Date: Sat, 28 Apr 2001 01:14:13 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Benchmark.pm is REALLY inaccurate?
Message-Id: <slrn9ek6b5.mm6.abigail@tsathoggua.rlyeh.net>
xris (xris@dont.send.spam) wrote on MMDCCXCVI September MCMXCIII in
<URL:news:xris-858133.00521227042001@news.evergo.net>:
-: and here everyone was telling me that Benchmark was such a good
-: indicator of the speed of various routines... so how come when I run
-: the same test three times in a row, I get three VERY different results?
-:
-: > ./test.pl
-: Benchmark: timing 50000 iterations of 1, 2, 3, 4, 5...
-: 1: 2 secs ( 1.57 usr 0.00 sys = 1.57 cpu)
-: 2: 2 secs ( 1.53 usr 0.01 sys = 1.54 cpu)
-: 3: 3 secs ( 1.56 usr 0.00 sys = 1.56 cpu)
-: 4: 4 secs ( 1.72 usr 0.00 sys = 1.72 cpu)
-: 5: 2 secs ( 1.77 usr 0.00 sys = 1.77 cpu)
-: > ./test.pl
-: Benchmark: timing 50000 iterations of 1, 2, 3, 4, 5...
-: 1: 2 secs ( 1.54 usr 0.01 sys = 1.55 cpu)
-: 2: 2 secs ( 1.56 usr 0.00 sys = 1.56 cpu)
-: 3: 3 secs ( 1.56 usr 0.01 sys = 1.57 cpu)
-: 4: 3 secs ( 1.80 usr 0.00 sys = 1.80 cpu)
-: 5: 8 secs ( 1.79 usr 0.00 sys = 1.79 cpu)
-: > ./test.pl
-: Benchmark: timing 50000 iterations of 1, 2, 3, 4, 5...
-: 1: 2 secs ( 1.58 usr 0.00 sys = 1.58 cpu)
-: 2: 1 secs ( 1.56 usr 0.00 sys = 1.56 cpu)
-: 3: 2 secs ( 1.55 usr 0.00 sys = 1.55 cpu)
-: 4: 2 secs ( 1.71 usr 0.00 sys = 1.71 cpu)
-: 5: 2 secs ( 1.77 usr 0.00 sys = 1.77 cpu)
I really fail to see the very different results. Here are the
results again, formatted slightly different:
1 2 3 A
1: 1.57 1.55 1.58 1.06%
2: 1.54 1.56 1.56 0.86%
3: 1.56 1.57 1.55 0.64%
4: 1.72 1.80 1.71 3.25%
5: 1.77 1.79 1.77 0.75%
The column marked 'A' are the maximum differences from the average of
the run. You see that in three out of five tests the maximum difference
from the average was less than 1%. In one case, it was just over, and
in the fifth case, the difference was a bit more than 3%.
Or are you only looking at the wall clock time? Well, that includes the
time your computer spend doing all kinds of other things, like writing
nasty mail to your boss, making an appointment with the hair dresser
to dye your hair pink, and gossipping with other computers about your
sex life.
Abigail
------------------------------
Date: Sat, 28 Apr 2001 01:17:48 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: extracting hostname from a url?
Message-Id: <slrn9ek6hs.mm6.abigail@tsathoggua.rlyeh.net>
Logan Shaw (logan@cs.utexas.edu) wrote on MMDCCXCVI September MCMXCIII in
<URL:news:9cc93d$ji8$1@charity.cs.utexas.edu>:
;;
;; IMHO, sometimes a module is overkill. If all you need is to do this
;; one thing, then typing "m<^(http://[^/]+/?)>i" is much easier and more
;; efficient than installing the URI module on every machine that will
;; ever use the script.
Well, it's much easier, but it's plain *WRONG*.
"www.perl.com:80" is not a valid hostname, but "http://www.perl.com:80/"
is a valid URL.
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'
------------------------------
Date: Fri, 27 Apr 2001 19:31:33 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Finding all elements in an array matching a certian criteria
Message-Id: <slrn9ek0al.4tk.tadmc@tadmc26.august.net>
nobull@mail.com <nobull@mail.com> wrote:
>tadmc@augustmail.com (Tad McClellan) writes:
>
>> Ron Hill <hillr@ugs.com> wrote:
>
>> >my %systems = ( 'riches' =>'1',
>> > 'loder' =>'1',
>> > 'yamaguch'=>'1',
>> > 'gerlich' =>'1');
>>
>> Do you get paid by the character? :-)
>
>> my @wanted = grep { my $id = $1 if /^([^_]+)/; $systems{$id} } @allfiles;
>
>Tad, are _you_ being paid by the character?
Everybody that pays me has plenty of character.
(in case any of them are reading this)
> my @wanted = grep { /^([^_]+)/ && $systems{$1} } @allfiles;
That _is_ better.
>> my $pattern = join '|', sort {$b cmp $a} keys %systems;
>
>sort? Do you also get paid a bonus for using sort?
No. But, since I usually work "by the job", I get paid more
if my code works even after executing: $systems{richeson} => 1;
^^^^^^
'cause then I don't have to spend more time patching it to work.
The left-to-right matching of alternatives has cost me a couple
hours of troubleshooting in the past, so I always guard against
keys that are prefixes of other keys by ensuring that the longer
one is leftmost.
Once bitten, twice shy.
:-)
>Double if you use
>a comparison function?
No, but I need them in ascending order to get the longest leftmost.
>> my @wanted = grep { /^$pattern/ } @allfiles;
>
>I think you meant:
>
>my @wanted = grep { /^($pattern)_/ } @allfiles;
That's better too. Now the sort() is no longer needed.
But I think this is probably better yet:
my @wanted = grep { /^${pattern}_/ } @allfiles;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 27 Apr 2001 20:22:56 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: First and last element in list loop
Message-Id: <m37l05hl73.fsf@dhcp9-172.support.tivoli.com>
On Sat, 28 Apr 2001, gtoomey@usa.net wrote:
> When using the list loop context
> for (@list)
> { .... }
>
> is there an easy way to test for the first and last element in the
> loop. Something like $_.first or $.last?
[snip]
> This there an elegant Perl solution for this?
As others have already indicated, not really. But I wonder, what type
of situation leads to this need?
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 28 Apr 2001 01:57:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: First and last element in list loop
Message-Id: <9cd82t$qtc$6@mamenchi.zrz.TU-Berlin.DE>
According to Ren Maddox <ren@tivoli.com>:
> On Sat, 28 Apr 2001, gtoomey@usa.net wrote:
>
> > When using the list loop context
> > for (@list)
> > { .... }
> >
> > is there an easy way to test for the first and last element in the
> > loop. Something like $_.first or $.last?
>
> [snip]
>
> > This there an elegant Perl solution for this?
>
> As others have already indicated, not really. But I wonder, what type
> of situation leads to this need?
my @animals = qw( birds cats dogs);
my $sentence = '';
foreach ( @animals ) {
if ( first() ) {
$sentence .= "There are $_";
} elsif ( last() ) {
$sentence .= " and $_.";
} else {
$sentence .= ", $_";
}
}
This may not be the most idiomatic way to do it, but it's not entirely
off the track.
Anno
------------------------------
Date: Sat, 28 Apr 2001 05:43:39 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: First and last element in list loop
Message-Id: <x7eludh947.fsf@home.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> According to Vinny Murphy <vmurphy@Cisco.Com>:
>> "Gregory Toomey" <gtoomey@usa.net> writes:
>>
>> > When using the list loop context
>> > for (@list)
>> > { .... }
>> >
>> > is there an easy way to test for the first and last element in the loop.
>> > Something like $_.first or $.last?
>>
>> Something like:
>>
>> my @a = ( "A" .. "Z");
AS> what about @a = ( 1 ) x 100; ?
>> for ( @a ) {
>> print "first " if $a[0] eq $_;
>> print "last " if $a[-1] eq $_;
>> print "$_\n";
>> }
AS> This is only an option if all enelemets in the list are distinct.
then use refs and it works fine:
@a = ( 1 ) x 4 ;
foreach $a ( @a ) {
print \$a, " $a\n" ;
print "first $a\n" if \$a == \$a[0] ;
print "last $a\n" if \$a == \$a[$#a] ;
}
SCALAR(0xc3864) 1
first 1
SCALAR(0xcdb28) 1
SCALAR(0xd5040) 1
SCALAR(0xd5094) 1
last 1
note that comparing refs with == is faster than eq and uses numeric
compare in recent perls.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Sat, 28 Apr 2001 06:38:18 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: First and last element in list loop
Message-Id: <slrn9ekt7c.sh.tjla@thislove.dyndns.org>
"mein Luftkissenfahrzeug ist voll von den Aalen"
said Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) in
<9cd06s$qtc$1@mamenchi.zrz.TU-Berlin.DE>:
>Maybe one day we will get $# to mean the loop index in foreach. Then
>this will be more convenient.
I dunno though, wouldn't this break programs that do stuff like:
print "The index of the last item is $#array\n";
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Newton's Little-Known Seventh Law:
A bird in the hand is safer than one overhead.
------------------------------
Date: 28 Apr 2001 04:22:17 GMT
From: michal@gortel.phys.ualberta.ca
Subject: Re: How to down size /usr/bin/perl ?
Message-Id: <9cdghp$dd8$1@pulp.srv.ualberta.ca>
Pally Kuo <pally@axtronics.com.tw> wrote:
> what should I do if all I want is socket function ?
Current beta versions of gawk, and a new release coming RSN, have
support for a basic networking and may be suitable for what you need.
>> >I must make it to below 200k, in order to post into flash rom...
Stripped gawk on Linux/x86 is of that size order but this does not
include shared libraries. Good enough? Chopping of some pieces
may be not that simple. A size does depend on a processor type
for which you are compiling.
Michal
------------------------------
Date: 28 Apr 2001 06:39:53 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: Must send lots of emails
Message-Id: <9cdojp$spj$0@216.155.32.133>
In article <fuegetcqpvtii9n92umfu585427hj8fhfv@4ax.com>,
Rob Greenbank <rob@frii.com> wrote:
| From you posting, referencing "users", I'm assuming you have a
| legitimate reason (ie. these people are expecting this email).
|
| First, your spreadsheet can be exported into delimitetd text or
| there's modules that will allow you to read the .xls file.
|
| On the email piece, I've been there, done that, and it may not be
| quite as simple as you think. As far as the email part, I do have
| a couple of comments/suggestions:
| 1) Avoid using Sendmail. It's an excellend MTA, but not really
| designed for bulk emailings. It will do the trick, but only
| at a rate of a few thousand per hour. More recent versions
| are better, but still relatively slow. If you *have* to use
| sendmail, get the latest version and set up multiple queues.
| 2) If this is your own server, so you have the freedom to do so,
| take a look at "postfix". It has some great features that
| really help volume emailing, like domain sorting, threads,
| and delivery of multiple emails with a single connection.
| 3) Look at the "mail-bulkmail" module (available on CPAN). It
| looked to me like it is very capable of handling a list like
| this. You also would have the flexibility of adding your own
| features. It actually connects to the destination MTAs,
| rather than placing the burdon on your local MTA>
| 4) Even with a good bulk delivery program you may still run into
| problems. Many ISPs will block connections from a bulk mailer,
| legit or not (they have no way to know). I've seen this with
| AOL, and my guess is you'll have LOTS of AOL addresses.
| 5) Be ready to handle the bounces. Plan in advance where you
| want them to go and how to handle them. The best way is to
| use a script, which in Sendmail can be set up in a .forward
| file or in the "aliases" file. By processing them with a
| script as they arrive, you don't have to queue them. My
| experience suggests about a 10% bounce rate, although the
| sophistication of the user makes a difference there.
| 6) If this is a mailing that will happen again, plan to actually
| do something with those bounces -- ie. remove the recipient
| from the list if it's a hard bounce (no MX for the server, or
| unknown user returned by the server). You will also get
| things like vacation notices, that look like bounces,
| forwarding notices, and mailbox fulls -- you probably don't
| want to remove those from your list. If you're going to do
| this you need to plan on doing it right. Figure on spending
| several hours updating your list after your first mailing.
|
| Don't be discouraged -- this is complicated, a pain, and some of the
| issues will take time to work out, but it's a fun learning experience
| too.
Oy, this is too nice to waste.. and should probably wind up in the FAQ
somewhere.
along with the caveat " ... if you insist on doing this in Perl instead
of using something like Listserv, anyway..." :-)
--
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw";
# ( damn spammers. *shakes fist* take a hint. =:P )
------------------------------
Date: Fri, 27 Apr 2001 18:45:00 -0700
From: "Shay Harding" <sharding@ccbill.com>
Subject: Re: Regular expression for zip code
Message-Id: <9cd6pv$v18$1@node17.cwnet.frontiernet.net>
"xris" <xris@dont.send.spam> wrote in message
news:xris-E42280.19090227042001@news.evergo.net...
> In article <9ccn4o$11k4$1@node17.cwnet.frontiernet.net>,
> "Shay Harding" <sharding@ccbill.com> wrote:
>
> > > > s/\b(?<!\S)\d{5}(-\d{4})?(?!\S)\b/X/g;
> > >
> you're also using (?<!\S) which doesn't seem to work in all versions of
> perl, either. (I'm curious which versions it DOES work in, since i've
> wanted something that does what I think this does for quite awhile.
The (?<!...) works in Perl 5.6.0 and I believe this was added in Perl 5.005
along with the other
(?...) constructs.
> something like:
>
> $x =~ s/\b\d{5}(?=-\d{4})\b/X/g;
>
> would probably work better, unless for some reason he/she needs
> something more precise than \b as a border verification.
Problem with the above expression is that it does not catch things like
'12345-1234-1234' or even '12345' (unless you put a '?' before the last
'\b').
Since I don't even know what type(s) of data will be checked, it is best to
be thorough (IMO).
Where I work we process financial information so the following data could
appear:
Mr. Arthur Miller
111 N Central Ave.
Box 111
Phoenix, AZ 85307
Balance: $12345.00
If I were to simply rely on '\b', I would be in trouble. Even with a good
regex to determine what is and what is not a 'valid' zip code format
(thinking US only here), it does not mean that the zip code even exists. I
do believe, however, that '12345' is assigned to General Electric in NY.
Shay
------------------------------
Date: Fri, 27 Apr 2001 22:43:48 -0500
From: xris <xris@dont.send.spam>
Subject: Re: Regular expression for zip code
Message-Id: <xris-EF39FC.22434827042001@news.evergo.net>
In article <9cd6pv$v18$1@node17.cwnet.frontiernet.net>,
"Shay Harding" <sharding@ccbill.com> wrote:
> The (?<!...) works in Perl 5.6.0 and I believe this was added in Perl 5.005
> along with the other
> (?...) constructs.
doesn't work in the latest macperl (was too lazy to test it in linux)..
but I'll definitely have to play more with it.
> > $x =~ s/\b\d{5}(?=-\d{4})\b/X/g;
> > would probably work better, unless for some reason he/she needs
> > something more precise than \b as a border verification.
> Problem with the above expression is that it does not catch things like
> '12345-1234-1234' or even '12345' (unless you put a '?' before the last
> '\b').
like I said... "unless for some reason he/she needs something more
precise than \b" Regardless, the other example did NOT work, as it
included the -\d{4} in the match, which was to be replaced by "X".
> If I were to simply rely on '\b', I would be in trouble. Even with a good
> regex to determine what is and what is not a 'valid' zip code format
> (thinking US only here), it does not mean that the zip code even exists. I
> do believe, however, that '12345' is assigned to General Electric in NY.
well, at that point, you start breaking things up differently. look for
things in context - pull the ENTIRE thing out in one regex, etc.
Anyway, my point wasn't to argue about /b, but to mention that the
previous example masked out the trailing 4 digits, which it was supposed
to keep.
------------------------------
Date: Sat, 28 Apr 2001 01:42:42 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Storing the CGI object in my module?
Message-Id: <3AEA2079.B69A310D@rochester.rr.com>
Robert Pottschmidt wrote:
...
> My question is how do I store the CGI object and than reference it?
...
> RCP
...
In Perl, an object is a blessed reference. Since it is a reference, it
may be stored in a scalar variable (or anywhere else where a scalar may
be stored). The value stored in the scalar variable may later be used
the same as any other scalar variable, so there is nothing special about
objects other than method calls. Typically, you would get at your
object with method calls, like $return_value=$obj->method(@args), for
example. I suspect you are making it too hard -- it isn't. See the
following docs:
perldoc perlboot
perldoc perltoot
perldoc perltootc
perldoc perlobj
perldoc perlbot
And read "Object Oriented Perl" by Damian Conway.
--
Bob Walton
------------------------------
Date: 27 Apr 2001 19:55:05 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Strange string -> num conversion
Message-Id: <m3g0ethmhi.fsf@dhcp9-172.support.tivoli.com>
On 27 Apr 2001, anno4000@lublin.zrz.tu-berlin.de wrote:
> Thanks for that. Yes, that explains "19", even in the case (which
> I had overlooked) where the string is converted, though the latter
> would be a buglet in Perl. It doesn't explain the fractional 2.125
> the OP has repeatedly seen.
Agreed. 2.125 does seem to be strange on a whole nother level. That
would be 1.125 before the addition of 1 -- maybe it's a version string
somehow. No, that doesn't make sense, as it wouldn't get *printed* as
a version string....
Got it!
$ perl -le 'print "0x1.2" + 1'
2.125
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Sat, 28 Apr 2001 01:24:08 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Strange string -> num conversion
Message-Id: <slrn9ek6to.mm6.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCXCVI
September MCMXCIII in <URL:news:9ccr7g$ilk$2@mamenchi.zrz.TU-Berlin.DE>:
$$ According to Jean-Louis Leroy <jll63@easynet.be>:
$$ > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
$$ >
$$ > > Something is fishy. What Perl version are you using? On what
$$ > > system?
$$ >
$$ > I found out on a Red Hat 6.2 system that had perl 5.005. I don't have
$$ > access to it right now. The examples I posted were made on my home
$$ > computer (see below).
$$ >
$$ > Now if I try this on perl 5.6.0 on NT 4 in a vmware computer, I get
$$ > the expected result (i.e. 1).
$$ >
$$ > And when I try again on my computer at work (SUSe 7) I get 19 (looks
$$ > like 0x12 is interpreted as a hex number; makes sense).
$$
$$ In that case the quotes around "0x12" probably got eaten by a shell.
$$ The string "0x12" is 0 in numeric context. The fractional number you
$$ apparently got remains mysterious.
$$
$$ > So the problem would be...glibc??
$$
$$ Unlikely. That would have to be a pretty massive bug.
I do get the same behaviour as Jean-Louis with 5.6.1, 5.6.0, 5.005_03
and bleedperl.
Abigail
--
$; # A lone dollar?
=$"; # Pod?
$; # The return of the lone dollar?
{Just=>another=>Perl=>Hacker=>} # Bare block?
=$/; # More pod?
print%; # No right operand for %?
------------------------------
Date: Fri, 27 Apr 2001 18:50:16 -0700
From: "Shay Harding" <sharding@ccbill.com>
Subject: Re: Strange string -> num conversion
Message-Id: <9cd73r$lse$1@node17.cwnet.frontiernet.net>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9ccr7g$ilk$2@mamenchi.zrz.TU-Berlin.DE...
> According to Jean-Louis Leroy <jll63@easynet.be>:
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> >
> > > Something is fishy. What Perl version are you using? On what
> > > system?
> >
> > I found out on a Red Hat 6.2 system that had perl 5.005. I don't have
> > access to it right now. The examples I posted were made on my home
> > computer (see below).
> >
> > Now if I try this on perl 5.6.0 on NT 4 in a vmware computer, I get
> > the expected result (i.e. 1).
> >
> > And when I try again on my computer at work (SUSe 7) I get 19 (looks
> > like 0x12 is interpreted as a hex number; makes sense).
>
Curious if this isn't more OS dependant? I tried it with the following
configs:
RedHat 7 w/ Perl 5.6.0 === 2.125
Mandrake 7.2 w/ Perl 5.6.0 === 2.125
FreeBSD 3.5 w/ Perl 5.005_03 === 1
FreeBSD 4.2 w/ Perl 5.6.0 === 1
Seems all the Linux variants treat it the same but the FreeBSD boxes return
1?
Shay
------------------------------
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 787
**************************************