[18765] in Perl-Users-Digest
Perl-Users Digest, Issue: 933 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 18 18:10:44 2001
Date: Fri, 18 May 2001 15: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: <990223816-v10-i933@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 18 May 2001 Volume: 10 Number: 933
Today's topics:
Handling JPEGs without modules <ebo_mike-antispam-remove-t@hottmail.com>
Re: Handling JPEGs without modules <elijah@workspot.net>
Re: Handling JPEGs without modules (Craig Berry)
Re: Has this already been done? <bart.lateur@skynet.be>
Re: Has this already been done? <davsoming@lineone.net>
Re: Has this already been done? (Craig Berry)
Help: using constants from inherited parent class ("Richard Stands")
Re: HTTP Login nobull@mail.com
Korn Shell Conversion <jgi@mindspring.com>
Re: Korn Shell Conversion <tony_curtis32@yahoo.com>
Re: Need Example creating Registry variable names nobull@mail.com
Re: non-blocking "print" on a client socket ?? nobull@mail.com
odbc transactions via dbi proxyserver <mljung@socrates.berkeley.edu>
Pronouncing ISA ("Richard Stands")
Re: Pronouncing ISA <brian@stevens.com>
Re: Pronouncing ISA (John Joseph Trammell)
Re: random ip-adress <mischief@velma.motion.net>
Script help <vbook@americasm01.nt.com>
Re: Script help <carlos@plant.student.utwente.nl>
Re: Script help (Craig Berry)
Re: Searching for Postal Code (John Joseph Trammell)
Re: Searching for Postal Code <keesh@users.pleaseremovethisbit.sourceforge.net>
Re: Searching for Postal Code nobull@mail.com
Re: Searching for Postal Code (reader of news)
Re: Searching for Postal Code <carlos@plant.student.utwente.nl>
Re: Searching for Postal Code <andras@mortgagestats.com>
Re: Searching for Postal Code <andras@mortgagestats.com>
Re: Stubborn regex won't work <godzilla@stomp.stomp.tokyo>
Re: Stubborn regex won't work (Greg Bacon)
Re: Stubborn regex won't work <skuo@mtwhitney.nsc.com>
Re: Stubborn regex won't work (Abigail)
Re: Stubborn regex won't work (Abigail)
The Perl version of this ASP would be.. <Ask@For-It.Com>
Re: Transliteration Creates A \r Character Accidently?? <clintp@geeksalad.org>
Re: Transliteration Creates A \r Character Accidently?? <godzilla@stomp.stomp.tokyo>
Re: Transliteration Creates A \r Character Accidently?? <godzilla@stomp.stomp.tokyo>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 May 2001 23:01:48 +0200
From: "Michael A. Krehan" <ebo_mike-antispam-remove-t@hottmail.com>
Subject: Handling JPEGs without modules
Message-Id: <9e42mi$goh$06$1@news.t-online.com>
[Basically a rephrased repost from clpmo. Sorry, but the original post
probably was a little bit hazy]
Hi,
I wanna create thumbnails from source graphics (mostly JPEG, other formats
would be cool too), resize them to a specific dimension and save a new JPEG
out of it. So FAQ, so good.
PROBLEM is that my hoster won't allow me to install modules. The only
available module is GD 1.19 which is incapable of handling JPEGs - the only
format I really need.
Is there anything I can do? How can I handle JPEG images without utilizing
modules? There are also no converting tools on the server, so I'm stuck with
pure perl code.
--
Michael A. Krehan
------------------------------
Date: 18 May 2001 21:25:21 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Handling JPEGs without modules
Message-Id: <eli$0105181722@qz.little-neck.ny.us>
In comp.lang.perl.misc,
Michael A. Krehan <ebo_mike-antispam-remove-t@hottmail.com> wrote:
> I wanna create thumbnails from source graphics (mostly JPEG, other formats
> would be cool too), resize them to a specific dimension and save a new JPEG
> out of it. So FAQ, so good.
>
> PROBLEM is that my hoster won't allow me to install modules. The only
> available module is GD 1.19 which is incapable of handling JPEGs - the only
> format I really need.
>
> Is there anything I can do? How can I handle JPEG images without utilizing
> modules? There are also no converting tools on the server, so I'm stuck with
> pure perl code.
Sounds like you have three choices:
A) Do the image processing elsewhere, then put the results on the server.
B) Write a pure-perl JPEG processor and use it in your code.
C) Find a hoster that will install the modules you need.
Elijah
------
fails to see how this could not be obvious
------------------------------
Date: Fri, 18 May 2001 21:51:38 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Handling JPEGs without modules
Message-Id: <tgb6ba44js1d7@corp.supernews.com>
Eli the Bearded (elijah@workspot.net) wrote:
: Sounds like you have three choices:
:
: A) Do the image processing elsewhere, then put the results on the server.
: B) Write a pure-perl JPEG processor and use it in your code.
: C) Find a hoster that will install the modules you need.
:
: fails to see how this could not be obvious
I think he was looking for hints on how to do B. I agree that A or C
would be preferable.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Fri, 18 May 2001 20:11:50 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Has this already been done?
Message-Id: <hd0bgtcfv55m1alj9502ou5lrqhne0uvlo@4ax.com>
Craig Berry wrote:
>Not so much a crap idea as one with limited utility. If you can guarantee
>that you won't get multiple requests for a unique id during a single
>second, this works as well as any other technique -- though you can get
>the same effect with less work by just using the seconds-since-epoch value
>returned by the time() function. However, guaranteeing that you won't get
>multiple requests in a single second can get arbitrarily tricky,
>especially as your application grows and mutates over time.
Take time since the epoch as a hex number. 8 characters. Append $$ as a
hex number. Likely 4 characters.
Do a sleep(1), for example in an END block, and this makes sure you
don't release the current PID before this second is over. So the next
copy of this script running can not get this PID assigned until the
time() has changed.
--
Bart.
------------------------------
Date: Fri, 18 May 2001 21:53:41 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Has this already been done?
Message-Id: <tgb2q0jugfvkbb@corp.supernews.co.uk>
> :
> : Today's date 18:05:01
> : Time 10:41:21
> : concatenation= "180501104121" =Unique 12 digit ID
> :
> : If its a crap idea, well OK.
>
> Not so much a crap idea as one with limited utility. If you can guarantee
> that you won't get multiple requests for a unique id during a single
> second, this works as well as any other technique -- though you can get
> the same effect with less work by just using the seconds-since-epoch value
> returned by the time() function. However, guaranteeing that you won't get
> multiple requests in a single second can get arbitrarily tricky,
> especially as your application grows and mutates over time.
I was thinking more in terms of using the "whole entity" to create any
number of Unique_Name variables assigned to a file upload or directory
perhaps, which readily would produce a label at a glance with "inbuilt" time
stamp. However- As far as gauranteeing singular requests and avoiding
simultaneous actions I'm not sure at all what to do here ? Maybe there's
some delay or queue mechenizm I could employ?
>
> : If there is a module which is better, (in the sense of output being
easily
> : readable-and readily understood, meaningful) or gives similar output
then I
> : don't wish to reinvent the wheel right?
>
> No module that I know of. In general, assigning unique IDs without
> depending on time-separated requests involves stashing information about
> what IDs have already been used in a persistent file, or using key
> generation facilities in a database. This isn't the sort of thing which
> can be easily encapsulated as a stand-alone module.
Maybe my idea isn't so crackpot afterall? I dunno.
As I already stated, I'm new to perl and would appreciate any advice how to
approach this one. I mean, It may not be the "best" or "ideal" but still
worth looking at from my prospective of learning something. I learn from my
mistakes and usually make plenty all the way, and so learn pretty fast. lol
Thanks for your advice.
David Soming
------------------------------
Date: Fri, 18 May 2001 21:13:54 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Has this already been done?
Message-Id: <tgb44in02heo9f@corp.supernews.com>
Bart Lateur (bart.lateur@skynet.be) wrote:
: Take time since the epoch as a hex number. 8 characters. Append $$ as a
: hex number. Likely 4 characters.
:
: Do a sleep(1), for example in an END block, and this makes sure you
: don't release the current PID before this second is over. So the next
: copy of this script running can not get this PID assigned until the
: time() has changed.
There are infinite ways to patch the basic concept. Each has strengths
and weaknesses (yours, for example, might involve high additional process
overhead if the process might otherwise have been freed in 0.03 seconds).
My point is only that, given that the raw time needs to be patched so much
to make it really useful as a unique ID, why not just bite the bullet and
manufacture your own unique IDs (from, say, a sequential integer
appropriately persisted and mutexed) directly?
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Fri, 18 May 2001 21:54:32 +0000 (UTC)
From: rstands@hotmail.com ("Richard Stands")
Subject: Help: using constants from inherited parent class
Message-Id: <F150mqn4pxUm1Ueqjaa0000c045@hotmail.com>
This must be fairly common but I can't find an example in my ActiveState
installation nor any reference to it in AS's docs, Camel or Conway's OOP. I
am sub-classing a package. The parent(SUPER) package allows exporting some
constants e.g.:
use SuperClass qw(:CONSTANTS);
The sub-class inherits this way:
package SubClass;
use base qw(SuperClass);
I want the script that ultimately uses the SubClass to have access to the
exported constants from the SuperClass but I'm not sure how to get at them.
If I don't do anything I get something like:
use strict;
use SubClass;
print "constant " . MY_CONSTANT;
Bareword "MY_CONSTANT" not allowed while "strict subs" in use at test.pl
line 6.
Which I know means that the constants aren't available in the test script's
name space. If I try to import them from the test script I get something
like:
"CONSTANTS" is not defined in %SubClass::EXPORT_TAGS at
D:/Perl/lib/Exporter/Heavy.pm line 75
Wrong :o( . If I try something (silly) like this in the sub-class:
package SubClass;
use base "Super \":CONSTANTS\"";
I get yelled at again:
syntax error at (eval 1) line 1, near "require SuperClass ":ERROR_CODES""
...propagated at D:/Perl/lib/base.pm line 62.
What's the secret syntax and where does it go?
-Rich
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
--
Posted from [63.66.71.66] by way of f150.law11.hotmail.com [64.4.17.150]
via Mailgate.ORG Server - http://www.Mailgate.ORG
------------------------------
Date: 18 May 2001 20:30:19 +0100
From: nobull@mail.com
Subject: Re: HTTP Login
Message-Id: <u9lmnump4k.fsf@wcl-l.bham.ac.uk>
"Mike Mesarch" <blah@blah.com> writes:
> I would like to download some files from an web site, but the site requires
> me to pass my username and password. How can I have perl pass this
> information when prompted?
Are we talking basic authentication or forms and cookies?
For basic authentication see the examples of basic authentication in
the LWP manuals.
For forms and cookies, give the LWP::UserAgent a cookie jar and then
submit the login form before you try to download.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 18 May 2001 18:18:21 -0400
From: "John Irwin" <jgi@mindspring.com>
Subject: Korn Shell Conversion
Message-Id: <9e43j5$gnp$1@slb5.atl.mindspring.net>
Can anyone suggest a source of a Korn Shell to Perl conversion utility?
--
John Irwin
jgi@mindspring.com
919-832-3437
------------------------------
Date: 18 May 2001 16:23:49 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Korn Shell Conversion
Message-Id: <87ofsq9wre.fsf@limey.hpcc.uh.edu>
>> On Fri, 18 May 2001 18:18:21 -0400,
>> "John Irwin" <jgi@mindspring.com> said:
> Can anyone suggest a source of a Korn Shell to Perl
> conversion utility? --
A programmer?
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: 18 May 2001 20:24:41 +0100
From: nobull@mail.com
Subject: Re: Need Example creating Registry variable names
Message-Id: <u9ofsqmpdy.fsf@wcl-l.bham.ac.uk>
"Frank van Geesink" <vGeesink@Planet.NL> writes:
> Here is the test I'm working on.
I do not believe you. I think there are a lot of transcription
errors. This makes it impossible to tell what is your real problem
and what is a transcription error.
> use Win32::Registry;
Have you looked at the documentation of Win32::Registry....
DESCRIPTION
NOTE: This module provides a very klunky interface to access the
Windows registry, and is not currently being developed actively.
It only exists for backward compatibility with old code that uses it.
For more powerful and flexible ways to access the registry, use
Win32::TieRegistry.
> my $Register="Software\\Funstuff";
> my $hkey, $SubKey;
>
> $HKEY_LOCAL_MACHINE->Open($Register,$hkey) || die $!;
> $Key="Frank";
> $hkey->Create($New,$SubKey);
> $hkey->SetValue($Key,REG_SZ,'Hello');
> $hkey->Close();
>
> The program creates a subkey "Frank" an places a default variabele with the
> value "Hello".
No it doesn't.
> I would like to give this value a name so I get in subkey
> "Frank" a variable named "Isay" with the value "Hello". Are there other
> optios then $SubKey, I.e. $SubVar?
It's just a variable, you can call it $YesWeHaveNoBananas if you like.
> Can somebody give me a hand?
use Win32::TieRegistry Delimiter => '/';
$Registry->{'LMachine/Software/Funstuff/'} = {
'Frank/' =>
{ '/Isay' => 'Hello' }
} or die "$^E";
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 18 May 2001 19:35:01 +0100
From: nobull@mail.com
Subject: Re: non-blocking "print" on a client socket ??
Message-Id: <u9zocamroq.fsf@wcl-l.bham.ac.uk>
Heiko Brey <cico@icomag.de> writes:
> Is there a possibility to make the "print" on the client socket
> something like "non-blocking" ?
No, non-blocking output must, AFAIK, use select() and syswrite().
I really wish someone would fix the non-blocking v STDIO issue. Maybe
PerlIO does this, I've not looked.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 18 May 2001 14:58:48 -0700
From: Matt Jung <mljung@socrates.berkeley.edu>
Subject: odbc transactions via dbi proxyserver
Message-Id: <3B059B18.A193F909@socrates.berkeley.edu>
Has anyone managed to enable transactions via dbi connecting remotely to
an MS Access database? I explicitly set AutoCommit to 0 in the database
handle and changed the relevant settings in the windows system dsn. But
it looks like the driver is ignoring these settings. I prepare the
statement handle and execute but the changes take place before I call
$h->rollback. Then the call to rollback of course returns fail status.
I have not found a single post in dejanews or a single page on the web
that confirms transactions are possible with this setup (i.e. dbi on
unix -> proxyserver on win2k -> DBD::ODBC -> MS Access). Any info would
be greatly appreciated.
------------------------------
Date: Fri, 18 May 2001 21:05:45 +0000 (UTC)
From: rstands@hotmail.com ("Richard Stands")
Subject: Pronouncing ISA
Message-Id: <F1443FcDddXAarwgAP900002ed3@hotmail.com>
I thought this was funny. In my (ActiveState) Perl documentation it says:
"This magical @ISA variable (pronounced ``is a'' not ``ice-uh'')".
Uh, OK... what? After all that is it "iz uh" or "iz ay"? I mean really,
'cause I'm not gonna spend one more dime of my company's $$$ until I can
properly pronounce the magical ISA! ;o) Cheers.
-Rich
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
--
Posted from [63.66.71.66] by way of f144.law11.hotmail.com [64.4.17.144]
via Mailgate.ORG Server - http://www.Mailgate.ORG
------------------------------
Date: Fri, 18 May 2001 15:45:28 -0600
From: Brian Stevens <brian@stevens.com>
Subject: Re: Pronouncing ISA
Message-Id: <3B0597F8.8107BF56@stevens.com>
Richard Stands wrote:
>
> I thought this was funny. In my (ActiveState) Perl documentation it says:
>
> "This magical @ISA variable (pronounced ``is a'' not ``ice-uh'')".
>
> Uh, OK... what? After all that is it "iz uh" or "iz ay"? I mean really,
The variable is pronounce "at-iz-uh"
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Brian Stevens STEVENS.COM, Inc.
brian@stevens.com (303)638-1366
Systems Administration Consultant
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: Fri, 18 May 2001 21:47:45 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Pronouncing ISA
Message-Id: <slrn9gb3nh.9ne.trammell@bayazid.hypersloth.net>
On Fri, 18 May 2001 21:05:45 +0000 (UTC), Richard Stands wrote:
> I thought this was funny. In my (ActiveState) Perl documentation it says:
>
> "This magical @ISA variable (pronounced ``is a'' not ``ice-uh'')".
>
> Uh, OK... what? After all that is it "iz uh" or "iz ay"? I mean really,
> 'cause I'm not gonna spend one more dime of my company's $$$ until I can
> properly pronounce the magical ISA! ;o) Cheers.
It's *spelled* ISA, but it's pronounced "throat-warbler mangrove".
Hope that helps.
--
Just Another Perl Hacker.
------------------------------
Date: Fri, 18 May 2001 19:34:01 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: random ip-adress
Message-Id: <tgau99mdl3tjf0@corp.supernews.com>
M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
> In article <u9d79agwk8.fsf@wcl-l.bham.ac.uk>, <nobull@mail.com> wrote:
>>Have you considered string concatenation?
>>
>>int ( rand * 256) . '.' . int ( rand * 256) . '.' . int ( rand * 256) . '.' . int ( rand * 256)
>>
>>Of course you could also do something like:
>>
>>join '.', map { int ( rand * 256) } 1..4
> You obviously haven't tried that:
> perl -wle 'print join ".", map { int ( rand * 256) } 1..4'
> Argument "*main::256" isn't numeric in rand at -e line 1.
> Argument "*main::256" isn't numeric in rand at -e line 1.
> Argument "*main::256" isn't numeric in rand at -e line 1.
> Argument "*main::256" isn't numeric in rand at -e line 1.
> 0.0.0.0
You are correct that it does not work. It's not far off, though.
$ perl -wle 'print join q{.}, map { int ((rand) * 256 ) } 1..4;'
197.86.146.146
$ perl -wle 'print join q{.}, map { int ( rand() * 256 ) } 1..4;'
147.195.220.35
$ perl -wle 'print join q{.}, map { int ( rand 256) } 1..4;'
110.34.98.190
Why q{rand * 256} causes so much trouble is not immediately
apparent. It indeed does look like calling rand with no arguments,
then taking the results times a number. What you show is that
perl doesn't see it that way. Whether or not that's a good thing
is left as an exercise.
The main thing to remember, IMHO, is that when something can be
fixed with a one-character change to a one-line script, most people
would rather see how to fix it than to simply hear that it is wrong.
Chris
--
Parking for people we like only. All other vehicles will be vandalized.
------------------------------
Date: Fri, 18 May 2001 16:12:16 -0400
From: "Methods, Verification [SKY:1G20:EXCH]" <vbook@americasm01.nt.com>
Subject: Script help
Message-Id: <3B058220.CA73003C@americasm01.nt.com>
This script I wrote is supposed to search through a file for lines which
match a pattern, then cut them and paste them into a new file. However,
I get no output, and my source file gets erased. Could anyone please
tell me what I'm doing wrong? Any help would greatly be appreciated.
Thanks.
#!/usr/bin/perl -w
use strict;
my $srcdir = "/home/perl";
my $src = "$srcdir/updates.txt"; # Source file, one to be
manipulated
my $dst = "$srcdir/destination.txt"; # Destination file, one to be
written to
open(DEST, ">>$dst") || die "Unable to open $dst : $!\n";
open(SRC, "<$src") || die "Unable to open $src : $!\n";
my @contents = <SRC>;
close SRC;
open (SRC, ">$src") || die "Unable to open $src : $!\n";
foreach (@contents) {
while(<SRC>)
{
my $Line = $_;
#foreach $Pattern (@patterns)
{
if($Line =~ /UPD|TRSR|PRS/) {
chomp $_;
#if (m/UPD: /) {
print DEST "$_\n";
print "Found $_ and printed it to $dst\n";
} else {
print SRC "$_\n";
}
}
}
}
close SRC;
close DEST;
------------------------------
Date: Fri, 18 May 2001 22:45:59 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: Script help
Message-Id: <9e41ej$d3v$1@dinkel.civ.utwente.nl>
this bastard: open (SRC, ">$src") is overwriting your source files
carlos
"Methods, Verification [SKY:1G20:EXCH]" <vbook@americasm01.nt.com> wrote in
message news:3B058220.CA73003C@americasm01.nt.com...
> This script I wrote is supposed to search through a file for lines which
> match a pattern, then cut them and paste them into a new file. However,
> I get no output, and my source file gets erased. Could anyone please
> tell me what I'm doing wrong? Any help would greatly be appreciated.
> Thanks.
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $srcdir = "/home/perl";
>
> my $src = "$srcdir/updates.txt"; # Source file, one to be
> manipulated
> my $dst = "$srcdir/destination.txt"; # Destination file, one to be
> written to
>
> open(DEST, ">>$dst") || die "Unable to open $dst : $!\n";
>
> open(SRC, "<$src") || die "Unable to open $src : $!\n";
> my @contents = <SRC>;
> close SRC;
>
> open (SRC, ">$src") || die "Unable to open $src : $!\n";
> foreach (@contents) {
>
> while(<SRC>)
> {
> my $Line = $_;
> #foreach $Pattern (@patterns)
> {
> if($Line =~ /UPD|TRSR|PRS/) {
> chomp $_;
> #if (m/UPD: /) {
> print DEST "$_\n";
> print "Found $_ and printed it to $dst\n";
> } else {
> print SRC "$_\n";
> }
> }
> }
> }
> close SRC;
> close DEST;
>
------------------------------
Date: Fri, 18 May 2001 21:22:05 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Script help
Message-Id: <tgb4jtg31un826@corp.supernews.com>
Methods, Verification [SKY:1G20:EXCH] (vbook@americasm01.nt.com) wrote:
[snip]
: open(SRC, "<$src") || die "Unable to open $src : $!\n";
: my @contents = <SRC>;
: close SRC;
:
: open (SRC, ">$src") || die "Unable to open $src : $!\n";
[snip]
: while(<SRC>)
You're not going to get very far looping on input from an output-only file
handle.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Fri, 18 May 2001 18:23:06 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Searching for Postal Code
Message-Id: <slrn9ganns.8ll.trammell@bayazid.hypersloth.net>
On Fri, 18 May 2001 19:02:34 GMT, Jean Cooper wrote:
[snip]
> if ($ARGV[0] =~ s/[a-z][0-9][a-z]\s[0-9][a-z][0-9]/i {
^^^ ^^^ ^^^
Shirley you mean [A-Z] ?
--
To think intelligently about copyrights, patents or trademarks, you must
think about them separately. The first step is declining to lump them
together as "intellectual property". - Richard Stallman
------------------------------
Date: Fri, 18 May 2001 19:27:33 +0100
From: "Ciaran McCreesh" <keesh@users.pleaseremovethisbit.sourceforge.net>
Subject: Re: Searching for Postal Code
Message-Id: <9e3pe6$una$1@newsg3.svr.pol.co.uk>
In article <slrn9ganns.8ll.trammell@bayazid.hypersloth.net>, "John Joseph
Trammell" <trammell@bayazid.hypersloth.invalid> wrote:
> On Fri, 18 May 2001 19:02:34 GMT, Jean Cooper wrote: [snip]
>> if ($ARGV[0] =~ s/[a-z][0-9][a-z]\s[0-9][a-z][0-9]/i {
> ^^^ ^^^ ^^^
> Shirley you mean [A-Z] ?
No, he has the /i switch, and (if he's UK like I guess he is) postcodes
can be in either case.
Isn't ARGV split by spaces by default? Is that the problem?
--
Ciaran McCreesh
mail: keesh@users.sourceforge.net
web: http://www.opensourcepan.com/
------------------------------
Date: 18 May 2001 19:31:35 +0100
From: nobull@mail.com
Subject: Re: Searching for Postal Code
Message-Id: <u93da2o6ew.fsf@wcl-l.bham.ac.uk>
trammell@bayazid.hypersloth.invalid (John Joseph Trammell) writes:
> On Fri, 18 May 2001 19:02:34 GMT, Jean Cooper wrote:
> [snip]
> > if ($ARGV[0] =~ s/[a-z][0-9][a-z]\s[0-9][a-z][0-9]/i {
> ^^^ ^^^ ^^^
> Shirley you mean [A-Z] ?
No, s/he doesn't, and stop calling him/her 'Shirley'!
(Hint: note the /i)
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 18 May 2001 19:31:58 GMT
From: newsreader@mediaone.net (reader of news)
Subject: Re: Searching for Postal Code
Message-Id: <slrn9gau4o.en5.newsreader@dragon.universe>
On Fri, 18 May 2001 19:02:34 GMT,
Jean Cooper <tlc3data@hincksdellcrest.org> wrote:
>Hi,
>
>I'm trying to search through some text and find the Postal Code
some text ? where is that text?
>
>open (PC, "PCFile.txt") or die "Can't find file\n";
>
>if ($ARGV[0] =~ s/[a-z][0-9][a-z]\s[0-9][a-z][0-9]/i {
>
are you looking postcode in PCFile.txt? if
so why are you looking in $ARGV[0]?
------------------------------
Date: Fri, 18 May 2001 22:44:04 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: Searching for Postal Code
Message-Id: <9e41d3$d3p$1@dinkel.civ.utwente.nl>
while (<PC>) {
if (/([a-z][0-9][a-z]\s?){2}/i){
s/\s$//g;
print "Found this: $_ , it seems to resemble a Postal Code\n";
}
}
carlos
------------------------------
Date: Fri, 18 May 2001 17:05:04 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Searching for Postal Code
Message-Id: <3B058E80.3DC53BD1@mortgagestats.com>
Jean Cooper wrote:
>
> Hi,
>
> I'm trying to search through some text and find the Postal Code
> (Canadian). The form of the PC is M4M 2B2. So I wrote a little Perl
> script, which isn't working too well. If anyone can let me know where
> I've gone wrong, I'd appreciate it.
>
> open (PC, "PCFile.txt") or die "Can't find file\n";
>
> if ($ARGV[0] =~ s/[a-z][0-9][a-z]\s[0-9][a-z][0-9]/i {
>
> print "Found something that resembles a Postal Code\n"
>
> }
>
> Jean
Couple of things:
1) Presumably your postal codes are hidden somewhere in PCFile.txt and
not on the command line, so you should not be looking for them i
$ARGV[0].
2) You want the m// operator, not s/// in the pattern match, right?
3) The left parenthesis after the if is unmatched.
How about something like this:
while (<DATA>){
if (m/[a-z][0-9][a-z]\s[0-9][a-z][0-9]/i) {
print "Found something that resembles a Postal Code in this line:\n
$_\n"
};
};
__DATA__
This is almost like a Postal Code: M3Q8U9 are you sure you want to
exclude it?
This is a good one: I9U 7U7.
Oops, here's a false match (has a tab instead of a space in the middle):
R4T 7Q1
Another kosher one: U6Y 8H9.
When I run it, I get:
C:\WINDOWS\Desktop>perl -w match.pl
Found something that resembles a Postal Code in this line:
This is a good one: I9U 7U7.
Found something that resembles a Postal Code in this line:
Oops, here's a false match (has a tab instead of a space in the
middle): R4T
7Q1
Found something that resembles a Postal Code in this line:
Another kosher one: U6Y 8H9.
Minor details:
It's good practice to check the results of a file open, but it's even
better to include $! in the error message. "Can't find file" may not be
the real reason why your file open failed. (Maybe you don't have the
right privileges?)
You may also want to think about what kind and what amount of white
space you will allow between the two blocks of three characters.
------------------------------
Date: Fri, 18 May 2001 17:10:26 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Searching for Postal Code
Message-Id: <3B058FC2.7928F6B@mortgagestats.com>
carlos wrote:
>
> while (<PC>) {
> if (/([a-z][0-9][a-z]\s?){2}/i){
> s/\s$//g;
> print "Found this: $_ , it seems to resemble a Postal Code\n";
> }
> }
>
> carlos
Except that this matches
letter-number-letter-space-letter-number-letter, when the OP is trying
to match letter-number-letter-space-number-letter-number.
------------------------------
Date: Fri, 18 May 2001 12:37:43 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Stubborn regex won't work
Message-Id: <3B057A07.AB0382C5@stomp.stomp.tokyo>
William Cardwell wrote:
> In the following, I'm trying to pull the "ERI000001" in every case,
> but I can't get it.
(snipped data and regex code)
You might find an index and substring method to
be a little easier. Your circumstances seem
perfect for this.
My test script, at first glance, appears to be
three methods. It is actually the same method
displaying increasing obfuscation. My preference
is the first method which is easy to read and
understand being written in Plain English.
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
$x='DISK02:[USERS.EUSWILC]ERI000001.INO;1';
$y='DISK02:[USERS.EUSWILC]ERI000001.;1';
$z='DISK02:[USERS.EUSWILC]ERI000001.';
$w='DISK02:[USERS.EUSWILC]ERI000001.INO';
for $t ($x,$y,$z,$w)
{
$start = index ($t, "]") + 1;
$stop = index ($t, ".", $start);
$t = substr ($t, $start, $stop - $start);
print "$t\n";
}
print "\n\n";
$x='DISK02:[USERS.EUSWILC]ERI000001.INO;1';
$y='DISK02:[USERS.EUSWILC]ERI000001.;1';
$z='DISK02:[USERS.EUSWILC]ERI000001.';
$w='DISK02:[USERS.EUSWILC]ERI000001.INO';
for ($x,$y,$z,$w)
{
$start = index ($_, "]") + 1;
$stop = index ($_, ".", $start);
print substr ($_, $start, $stop - $start), "\n";
}
print "\n\n";
$x='DISK02:[USERS.EUSWILC]ERI000001.INO;1';
$y='DISK02:[USERS.EUSWILC]ERI000001.;1';
$z='DISK02:[USERS.EUSWILC]ERI000001.';
$w='DISK02:[USERS.EUSWILC]ERI000001.INO';
for ($x,$y,$z,$w)
{ print substr ($_, index ($_, "]") + 1,
index ($_, ".", index ($_, "]")) -
index ($_, "]") - 1), "\n";
}
exit;
PRINTED RESULTS:
________________
ERI000001
ERI000001
ERI000001
ERI000001
ERI000001
ERI000001
ERI000001
ERI000001
ERI000001
ERI000001
ERI000001
ERI000001
------------------------------
Date: Fri, 18 May 2001 20:00:34 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Stubborn regex won't work
Message-Id: <tgavr2dnhfq559@corp.supernews.com>
In article <3B055618.1AB65E3C@am1.ericsson.se>,
William Cardwell <EUSWMCL@am1.ericsson.se> wrote:
: In the following, I'm trying to pull the "ERI000001" in every case, but
: I can't get it.
: Can anyone help?
Have you read the 'sexegers' article on www.perl.com[*]? In this case,
the technique is useful:
% cat try
#! /usr/local/bin/perl -w
use strict;
my @files = qw(
DISK02:[USERS.EUSWILC]ERI000001.INO;1
DISK02:[USERS.EUSWILC]ERI000001.;1
DISK02:[USERS.EUSWILC]ERI000001.
DISK02:[USERS.EUSWILC]ERI000001.INO
);
for (map scalar reverse, @files) {
if (/^.*?\.(\w+)/) {
print scalar reverse($1), "\n";
}
}
% ./try
ERI000001
ERI000001
ERI000001
ERI000001
[*] <URL:http://www.perl.com/pub/2001/05/01/expressions.html>
Sorry about your VMS infection. :-)
Hope this helps,
Greg
--
Neither a lofty degree of intelligence nor imagination nor both together go
to the making of genius. Love, love, love, that is the soul of genius.
-- Mozart
------------------------------
Date: Fri, 18 May 2001 13:05:34 -0700
From: "S. Kuo" <skuo@mtwhitney.nsc.com>
Subject: Re: Stubborn regex won't work
Message-Id: <Pine.GSO.4.21.0105181303110.11121-100000@mtwhitney.nsc.com>
On Fri, 18 May 2001, William Cardwell wrote:
> In the following, I'm trying to pull the "ERI000001" in every case, but
> I can't get it.
> Can anyone help?
>
>
> $x='DISK02:[USERS.EUSWILC]ERI000001.INO;1';
> $y='DISK02:[USERS.EUSWILC]ERI000001.;1';
> $z='DISK02:[USERS.EUSWILC]ERI000001.';
> $w='DISK02:[USERS.EUSWILC]ERI000001.INO';
>
> # Last word string terminated by a period
> for $t ($x,$y,$z,$w) {
> if ($t =~ /(\w+)\.\G/g) {$a = $1} # this for example doesn't work
> print "$a\n";
> }
My thought was to reverse the input string:
# Last word string terminated by a period
for $t ($x,$y,$z,$w) {
if (reverse($t) =~ /\.(\w+)/) {
$a = reverse($1);
print $a, "\n";
}
}
--
Cheers,
Steve
------------------------------
Date: Fri, 18 May 2001 20:51:18 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Stubborn regex won't work
Message-Id: <slrn9gb2q6.87b.abigail@tsathoggua.rlyeh.net>
William Cardwell (EUSWMCL@am1.ericsson.se) wrote on MMDCCCXVII September
MCMXCIII in <URL:news:3B055618.1AB65E3C@am1.ericsson.se>:
][ In the following, I'm trying to pull the "ERI000001" in every case, but
][ I can't get it.
][ Can anyone help?
][
][
][ $x='DISK02:[USERS.EUSWILC]ERI000001.INO;1';
][ $y='DISK02:[USERS.EUSWILC]ERI000001.;1';
][ $z='DISK02:[USERS.EUSWILC]ERI000001.';
][ $w='DISK02:[USERS.EUSWILC]ERI000001.INO';
][
][ # Last word string terminated by a period
][ for $t ($x,$y,$z,$w) {
][ if ($t =~ /(\w+)\.\G/g) {$a = $1} # this for example doesn't work
][ print "$a\n";
][ }
Why are you using \G and /g? That doesn't make any sense to me.
Abigail
--
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();
------------------------------
Date: Fri, 18 May 2001 20:51:51 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Stubborn regex won't work
Message-Id: <slrn9gb2r7.87b.abigail@tsathoggua.rlyeh.net>
Ciaran McCreesh (keesh@users.pleaseremovethisbit.sourceforge.net) wrote
on MMDCCCXVII September MCMXCIII in <URL:news:9e3me7$52l$1@news6.svr.pol.co.uk>:
][ In article <3B055618.1AB65E3C@am1.ericsson.se>, "William Cardwell"
][ <EUSWMCL@am1.ericsson.se> wrote:
][ > # Last word string terminated by a period
][ > for $t ($x,$y,$z,$w) {
][
][ Surely foreach ?
Why? Is there a difference?
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: Fri, 18 May 2001 20:19:25 +0100
From: "Robb Meade" <Ask@For-It.Com>
Subject: The Perl version of this ASP would be..
Message-Id: <9e3sgh$10b$1@newsg3.svr.pol.co.uk>
Hi all,
I'm having a problem getting more than one line of text to send through to
my emails sent via a Perl script..
In my ASP code, if I use this
strMessage = Request.Form("Message") ' gets info from form
strMessage = Replace(strMessage, vbCRLF, "<br>")
then after entering this in the form..
Text Line 1
Text Line 2
I get this in an email
Text Line 1 <br><br> Text Line 2
So, I know that the ASP code is all working.
If I remove this, ie, the Replace part...
When I send the same, I only get this
Text Line 1
Its as if for some reason my script is going a little loopy, and losing
anything after the first line??
I was wondering if there was a Perl version of my above code that would
force the carriage return and hence display the other lines in the email?
Thanks in advance....
(the following is the code I'm using)
#!/usr/bin/perl -w
use strict;
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
my $site=param("site");
my
$target="http://www.kingswoodweb.net/clientmailingconfirm.asp?site=$site";
####################################
# new sub to retrieve mailing list #
####################################
sub send_to($)
{
my $file = shift;
my @list;
open(SEND, "< $file") or die "Could not open $file: $!";
@list = <SEND>;
close SEND;
return(@list);
}
sub send_mail {
my $sendmail="/usr/sbin/sendmail -t -oi";
my $from="mailing.list\@boomshankers.com";
my $subject=param("subject");
my $message=param("message");
############################################################
# return value of send_to sub is placed into your new list #
############################################################
my @email_list = send_to("email.txt");
##################################
# loop through each item in list #
##################################
for my $to (@email_list)
{
chomp $to;
open(MAIL, "|$sendmail") || die "Can't start sendmail: $!";
print MAIL<<END_OF_HEADER;
From: $from
To: $to
Subject: $subject
$message
END_OF_HEADER
close(MAIL);
} # for loop complete
}
send_mail();
print redirect( -url => $target );
Thanks in advance for any help available... :)
--
Robb Meade
Kingswood Web Services
www.kingswoodweb.net
------------------------------
Date: Fri, 18 May 2001 18:49:02 GMT
From: Clinton A. Pierce <clintp@geeksalad.org>
Subject: Re: Transliteration Creates A \r Character Accidently??
Message-Id: <jhragtgdibdvjbponprm5dj34v9utmna6d@4ax.com>
I can't replicate the problem at all using Perl 5.6 and Mozilla .9
(which is what I have handy).
On Fri, 18 May 2001 09:54:36 -0700, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:
>I have some subsequent articles which provide more information.
>Not so sure now this is actually Perl related. Kinda looks like
>I stumbled into a really rare data set which messes up Mozilla.
Have you considered capturing the output of the program (using
redirection) and simply serving it up as an static file? Or as a
local file on disk?
This would eliminate Perl entirely from suspicion.
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Fri, 18 May 2001 12:28:45 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Transliteration Creates A \r Character Accidently??
Message-Id: <3B0577ED.DECE8614@stomp.stomp.tokyo>
Clinton A. Pierce wrote:
> Godzilla! wrote:
> I can't replicate the problem at all using Perl 5.6 and Mozilla .9
> (which is what I have handy).
Dang! Earliest version of Mozilla I have is 1.2 !!
> >I have some subsequent articles which provide more information.
> >Not so sure now this is actually Perl related. Kinda looks like
> >I stumbled into a really rare data set which messes up Mozilla.
> Have you considered capturing the output of the program (using
> redirection) and simply serving it up as an static file? Or as a
> local file on disk?
> This would eliminate Perl entirely from suspicion.
This will highlight my ignorance, I am not sure what you mean
by a redirection and static file. Help? Do you mean print a
hardcopy page then access it with my browser?
I will follow your suggestion and try writing to a disk file
and discover if there is anything, to discover! I can translate
\r and \n into visible characters with my program editor and
actually "see" what is there, if anything.
Darn thing is, if a \r character is being generated, I cannot
see this in a DOS box nor in plaintext document source. I've
tried so darn many methods to "capture" whatever is there
and when I do try these methods, the darn glitch vanishes.
There are so many variables involved, just the slighest
changes, no matter how minor, cause this glitch to stop.
I cannot, so far, pinpoint this to a precise causation.
Sure wish I could pinpoint a cause. I would like to be
able to replicate this at will to determine if a larger
problem is lurking in perl core.
Just doesn't make sense. A \r character should not cause
a browser to create a blank line within a plaintext print.
I would expect a \n character but this doesn't show in
document source, which is plaintext as well!
I will write to disk, write to a static page if I understand
this correctly, pull a few other lame brain stunts. I will
post whatever I discover.
Thanks for your help! I had not considered what you suggest.
Godzilla!
------------------------------
Date: Fri, 18 May 2001 14:33:47 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Transliteration Creates A \r Character Accidently??
Message-Id: <3B05953B.18775FA@stomp.stomp.tokyo>
"Clinton A. Pierce" wrote:
(snipped)
> Have you considered capturing the output of the program (using
> redirection) and simply serving it up as an static file?
> Or as a local file on disk?
Writing to a disk file shows no error. Creating a
static plaintext page and static html page, then
accessing either with a browser shows no error.
GAK!
I've narrowed my code down significantly. Seems to
be related to spaces, a certain number printed in
a selected format.
Evidence more strongly suggests this is a browser
problem than a Perl problem. No clear answer though!
I'm not going to pursue this any further; this is
too frustrating and not worth much attention.
Thanks for your suggestions.
Godzilla!
------------------------------
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 933
**************************************