[16513] in Perl-Users-Digest
Perl-Users Digest, Issue: 3925 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 6 00:05:24 2000
Date: Sat, 5 Aug 2000 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965534708-v9-i3925@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 5 Aug 2000 Volume: 9 Number: 3925
Today's topics:
Re: bug in localtime()??? (J. B. Moreno)
Re: Can't locate object method "new" - CRYPT <gjm@bigfoot.com>
Re: Converting a number to another base <kalinabears@hdc.com.au>
Deleting an element from hash of hashes? <sumengen@hotelspectra.com>
Re: Dreaded 500 message (Gwyn Judd)
editing PDF files with Perl... possible? (Dico Reyers)
Editing.cfg file for use with anti-leech Perl script... (Cyber Thief)
Re: file upload using perl <starktdh@gmx.de>
good 'related stories' cgi script? calderas@my-deja.com
Re: good 'related stories' cgi script? <rob13@rock13.com>
Re: Is "exit()" really necessary? <bart.lateur@skynet.be>
Need help fixing a PerlShop problem <zipsiteslook@hotmail.com>
Perl Newbie Question <research@ev1.net>
Re: Perl Newbie Question (Prasanth A. Kumar)
Problem w/anchored match <adamsone@voyager.net>
Re: Problem w/anchored match <aqumsieh@hyperchip.com>
Re: Problem w/anchored match (Prasanth A. Kumar)
Re: Someone please explain the 'my' declaration. (Walt Mankowski)
Re: Stumped Again! <uri@sysarch.com>
Re: Stumped Again! <VincentMurphy@mediaone.net>
Re: Stumped Again! <dmeyers@panix.com>
Re: Stumped Again! <godzilla@stomp.stomp.tokyo>
Re: Tag attributes <godzilla@stomp.stomp.tokyo>
Re: Tag attributes (Keith Calvert Ivey)
Re: Win32::OLE and MS Excel Problem <montyh@defender.gpcc.itd.umich.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 5 Aug 2000 21:54:20 -0400
From: planb@newsreaders.com (J. B. Moreno)
Subject: Re: bug in localtime()???
Message-Id: <1eewn1f.zc5tme1oiuxb0N%planb@newsreaders.com>
Mike King @work <mikek@worldwebserver.com> wrote:
> Andras Malatinszky wrote:
> >
> > This is a feature, not a bug. The month in localtime is represented by a
> > number ranging from 0 to 11. January is represented by 0, February is 1...
-snip-
> I understand now. I did not comprehend this while reading the docs.
Why not? And why were you so convinced that it was a bug even after
being told there was no bug?
--
JBM
------------------------------
Date: Sun, 06 Aug 2000 01:15:40 +0100
From: Garry Mitchell <gjm@bigfoot.com>
To: GS <pleaseREPLYtotheGROUP@notrealdomain.com>
Subject: Re: Can't locate object method "new" - CRYPT
Message-Id: <398CAE2C.C0A36D6@bigfoot.com>
Have you tried the obvious:
use Crypt::CBC;
Regards,
Garry
GS wrote:
>
> I installed ActiveState's ActivePerl 5.6 build 616 and then went into PPM
> and did
>
> "install Crypt-Blowfish_PP" It said it installed fine.
>
> I then run code (CODE 1 BELOW) which checks for Crypt::CBC and it says
> that's OK. But when I try to use it (CODE 2 BELOW) I get this error:
>
> Can't locate object method "new" via package "Crypt::CBC"
>
> I'm a programmer but new to perl and modules. Could someone tell me what to
> do to fix this?
>
> CODE 1 EXCERPT
> print_message("Checking for Crypt::CBC...");
> $module = "CBC";
> eval "do $module";
> if (not $@) {
> print_message(" OK\n");
>
> CODE 2 EXCERPT
> $cipher = new Crypt::CBC(pack('H*', $WHATEVER{private_key}),
> $WHATEVER{crypt_type});
------------------------------
Date: Sun, 6 Aug 2000 13:29:19 +1000
From: "Rhonda Woodward" <kalinabears@hdc.com.au>
Subject: Re: Converting a number to another base
Message-Id: <WZ4j5.7$Mb1.1140@vic.nntp.telstra.net>
Hi,
There have been a few postings recently regarding converting a
number from one base to another.
I have been using the script below - running from the command
line on my Active Perl (hence all the "<STDIN>"s and "print"s).
It will convert positive integers from any base in the range
2 to 16, to any base in the range 2 to 16.
It does this by first converting to base 10, then to the second
specified base.
In the script below, $number is converted from base $base1 to
base $base2.
There is probably not a great demand for converting base 13 to
base 6 (for example) but if it is going to handle 2 to 8, 2 to 10,
2 to 16, 8 to 10, 8 to 16 and 10 to 16 (and vice versa) it might as
well do the rest.
The bulk of it is involved in ensuring that it is not being asked to
manipulate meaningless data or perform tasks for which it is not
designed (eg. treat 7G as a binary no. or convert to base 18).
(I suppose I should set it up as a sub routine and call it with its
three arguments , hmmm - next weekend.)
I would expect that it has been done before, though I (and apparently
some others) have been unable to find it.
Cheers,
Rob
$base1=<STDIN>; # Enter the base $number.
chomp $base1;
$number=<STDIN>; # Enter a number.
chomp $number;
$base2=<STDIN>; # Enter the base to which $number is to be #converted.
chomp $base2;
# check that the $base1 number contains only numeric characters
@base1byt=split(//,$base1);
foreach $base1byt (@base1byt) {
unless ($base1byt =~/[0-9]/) {
print "Neither base number can contain any non numeric characters";
exit;
}
}
# check that $base1 is not greater than 16
unless ($base1<=16) {
print "Neither base can be greater than 16";
exit;
}
# check that the number contains only hexadecimal characters
@byt=split(//,$number);
foreach $byt (@byt) {
unless ($byt =~/[0-9]|[A-F]/i) {
print "The number contains non hexadecimal characters";
exit;
}
}
# change any alpha hex characters to their numeric value
foreach $byt (@byt) {
$byt =~s/a/10/i;
$byt =~s/b/11/i;
$byt =~s/c/12/i; # can all this be put in one line?
$byt =~s/d/13/i;
$byt =~s/e/14/i;
$byt =~s/f/15/i;
}
# check that the entered number is a base $base1 number.
# eg. 183 is not a base 8 number.
foreach $byt (@byt) {
unless ($byt<$base1) {
print "$number is not a base $base1 number";
exit;
}
}
# check that the $base2 number contains only numeric characters
@base2byt=split(//,$base2);
foreach $base2byt (@base2byt) {
unless ($base2byt =~/[0-9]/) {
print "Neither base number can contain any non numeric characters";
exit;
}
}
# check that $base2 is not greater than 16
unless ($base2<=16) {
print "Neither base can be greater than 16";
exit;
}
if ($base1 != 10) { # no need to convert a number to itself.
# do the arithmetic
$num=0;
$ind=$#byt;
foreach $byt(@byt) {
$dec=$byt*($base1**$ind);
$num=$dec+$num;
$ind--;
}
}
else { # ie. if the given no. is a decimal.
$num=$number;
}
if ($base2 !=10) { # no need to convert a number to itself.
# convert the decimal $num to the desired base.
$d=$num%$base2;
$q=int($num/$base2);
@bin=(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F);
$b=$bin[$d];
if ($q==0) {
print "$number, base $base1 = $b, base $base2";
}
else {
while ($q!=0) {
$d=$q%$base2;
$q=int($q/$base2);
$b="$bin[$d]"."$b";
}
print "$number, base $base1 = $b, base $base2";
}
}
else
print "$number, base $base1 = $num, base 10";
}
--
Visit our website at http://www.kalinabears.com.au
------------------------------
Date: Sat, 5 Aug 2000 20:45:52 -0700
From: "Baris" <sumengen@hotelspectra.com>
Subject: Deleting an element from hash of hashes?
Message-Id: <398cdf07$1_1@goliath2.newsfeeds.com>
Hello,
I have a hash:
%hash = (
i1 => {a1=>1, a2=>2},
i2 => {a1=>4,a3=>6}
);
to erase i2 from this hash I am doing this:
undef %{$hash{i2}};
delete $hash{i2};
Is this good enough, especially in terms of cleaning memory?
Is there a perl doc for cleaning complex data structures?
Thanks,
Baris.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Sun, 06 Aug 2000 00:03:31 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Dreaded 500 message
Message-Id: <slrn8opb0h.1mk.tjla@thislove.dyndns.org>
I was shocked! How could Kokuryu <kokuryu2@hotmail.com>
say such a terrible thing:
>Well, it's a good thing I didnt bother posting any code up here -
>because the code works just fine!
I guess we can all sleep easier knowing that.
>Guess what? It all worked perfectly from then on.
*shrug* who cares? This is comp.lang.perl.misc not
comp.oh-my-god-my-computer-doesn't-work.drool.drool.drool.
>Next time, please read the message that someone posts rather than jump
>to the conclusion that there is something wrong with the code.
We did. If there is nothing wrong with the code then it's not a Perl
problem. If it's not a Perl problem then why post it here? There are
more appropriate newsgroups for this sort of thing. Next time I suggest
you familiarise yourself with the newsgroup before you post and stop
asking FAQ's.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Give your child mental blocks for Christmas.
------------------------------
Date: Sat, 05 Aug 2000 23:47:28 GMT
From: dico@internetworks.ca (Dico Reyers)
Subject: editing PDF files with Perl... possible?
Message-Id: <398ca742.621917@news1.pei.sympatico.ca>
Hi There,
I am wondering if one can edit PDF files with Perl (or PHP). I would
like someone to be able to go to a specific URL and edit a PDF... move
images/text? Is this possible?
Thanks,
-Dico
------------------------------
Date: Sat, 05 Aug 2000 23:59:40 GMT
From: fake@address.com (Cyber Thief)
Subject: Editing.cfg file for use with anti-leech Perl script...
Message-Id: <MT1j5.22733$RG6.1882758@bgtnsc05-news.ops.worldnet.att.net>
I've got a script that uses the "HTTP REFERER" to verify that user's who
download files from my site are actually at the site, and not some stolen link.
The script relies on a .cfg file to know which URLS are permitted to access my
files. In setting up this file, I was required to put in the URL like this:
http:\/\/internettrash.com\/users\/cyberthief\/
end
Two lines, right? So, I make this file on Notepad and upload it to the CGI-BIN
only to find all the info is bunched up together on one line. I run the program
and it tells me my own site is not permitted to access files! Is there anyway I
can edit this so the URL and the "end" command show up as separate lines. I
would also like to add a couple other URLS for access, but I can't because they
each require their own line, yet the text gets compressed together when I
upload in ASCII mode. I even tried uploading as binary. No dice. Any
suggestions?
--
Cyber Thief
http://internettrash.com/users/cyberthief/
http://wwp.mirabilis.com/83606927
cyberthief@deathsdoor.nospam.com (Remove the .nospam to reply)
1-800-226-0007 Box 233 (After Hours)
------------------------------
Date: Sun, 6 Aug 2000 03:33:54 +0200
From: "Johannes Stark" <starktdh@gmx.de>
Subject: Re: file upload using perl
Message-Id: <8migu2$ba8$1@merlin.rembrandtstr.bocholt.de>
Yes of course I will, but the problem is solved in cgi.pm and I want to
understand that problem.
So once more: does anyone really know, whats up with STDIN + perl + cgi +
posted data.
Thank you
------------------------------
Date: Sun, 06 Aug 2000 00:10:36 GMT
From: calderas@my-deja.com
Subject: good 'related stories' cgi script?
Message-Id: <8miadr$9tm$1@nnrp1.deja.com>
anyone know a good related stories script, that dynamically creates a
list of story titles that are similar to the main article on a selected
web page?
if you don't know what i mean this page has an example of it
http://www.ecommercetimes.com/news/viewpoint2000/view-000803-2.shtml
kramer
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 05 Aug 2000 22:21:06 -0400
From: "Rob - Rock13.com" <rob13@rock13.com>
Subject: Re: good 'related stories' cgi script?
Message-Id: <398CCB92.D56E704@rock13.com>
calderas@my-deja.com wrote:
>
> anyone know a good related stories script, that dynamically creates a
> list of story titles that are similar to the main article on a selected
> web page?
>
> if you don't know what i mean this page has an example of it
> http://www.ecommercetimes.com/news/viewpoint2000/view-000803-2.shtml
Sounds like a search engine. You could have it base similiarities
soley on title or on other content as well.
There might be specialized SE scripts for this, I dunno. Might look at
cgi-resources.com
--
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/
------------------------------
Date: Sat, 05 Aug 2000 22:12:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Is "exit()" really necessary?
Message-Id: <l74possfimbli171rqsq8ab8vra2evfftq@4ax.com>
Richard J. Rauenzahn wrote:
>I think all of you might want to reread the CERT advisory, paying
>particular attention to the date:
>
> http://x73.deja.com/getdoc.xp?AN=605122255.1
Note the date. Note the ID: "AF-2000-04-01". I think I can guess what
the "AF" stands for. Plus: the link is dead.
--
Bart.
------------------------------
Date: Sun, 06 Aug 2000 02:32:27 GMT
From: Joe <zipsiteslook@hotmail.com>
Subject: Need help fixing a PerlShop problem
Message-Id: <mfjposcq6qkb4o2oitlut7tvii0pqlqcvi@4ax.com>
http://www.fastoil.net/entry.htm
I don't know perl and my host[Web2010] can't figure out what is wrong
with my site either. I did install the PerlShop script with their help
and it has run fine in the past.
The PerlShop script I use was posting an error at the bottom of each
store page. The error stated something like "can't open to write". I
changed the permissions on some files and dir's and the error stopped.
Now, when a store html page is displayed the page never finishes
loading. I can see the whole page and place an order. I use IE5 and an
ISP. The Tech help at Web2010 gets the same result as I do. However,
AOL users , and maybe others, only get about 40% of the page loaded
and then it stops.
It looks like the perl script is trying to load something and can't
find it.
My host did make some corrections to a "shell" script that was not
working properly and was causing a cron job to malfunction. The cron
job automaticaly emails me the store orders.
I've tried running the html pages thru CSEHtmlvalidator4, removing
changes to the pages I've made, nothing seems to work.
Anyone have any ideas how to tackle this problem?
Thanks.
Take care,
Joe
******************************
zipsiteslook@hotmail.com
don't "look" to reply
******************************
------------------------------
Date: Sun, 06 Aug 2000 01:27:47 GMT
From: "Ken" <research@ev1.net>
Subject: Perl Newbie Question
Message-Id: <na3j5.1750$KO2.37087@typhoon.austin.rr.com>
I have a delimited file with data pertaining to each column. I am needing
to add dates into every 4th column. I'm not grasping the concept of reg
exp, but the columns are delimited by |. The layout of the file is as such.
data0|data1|data2|data3|data4|data5|data6|data7|...data29
The first date will need to be placed between data1 and data2, the next date
is then placed between data5 and data6.
TIA
Ken
------------------------------
Date: Sun, 06 Aug 2000 02:31:48 GMT
From: kumar1@home.com (Prasanth A. Kumar)
Subject: Re: Perl Newbie Question
Message-Id: <m31z035dd7.fsf@C654771-a.frmt1.sfba.home.com>
"Ken" <research@ev1.net> writes:
> I have a delimited file with data pertaining to each column. I am needing
> to add dates into every 4th column. I'm not grasping the concept of reg
> exp, but the columns are delimited by |. The layout of the file is as such.
>
> data0|data1|data2|data3|data4|data5|data6|data7|...data29
>
> The first date will need to be placed between data1 and data2, the next date
> is then placed between data5 and data6.
>
> TIA
> Ken
You could instead use 'split' to breakup the string into an array
based on the | delimiter. Then use 'splice' to insert or remove
array elements and finally use 'join' to put it back together with the
delimiter again being |.
--
Prasanth Kumar
kumar1@home.com
------------------------------
Date: Sat, 5 Aug 2000 21:25:45 -0400
From: "Eric Adamson" <adamsone@voyager.net>
Subject: Problem w/anchored match
Message-Id: <398cbed6$0$72393$2c3ea6f8@news.voyager.net>
I'm processing a text file, and wish to identify lines that contain phone
numbers. For the moment, I'm testing my routine by just printing them out.
I wish to find lines matching ###-####, with no other text appearing on the
line. Why doesn't the following work?
SAMPLE INPUT DATA:
555-3494
555-3949
448-3944 Bob Smith
MY SCRIPT:
#!/usr/bin/perl
open(IN, "<testfile.txt");
while (<IN>) {
if (/^\d\d\d-\d\d\d\d$/) {
print $_;
}
}
close IN;
I tried removing the anchors, and testing for a second condition -- that the
line have length=8 -- and *still* get no matches! Perl returns a length of
10 for the lines that I'm interested in -- chomping only takes it down to 9.
Lines are broken with linefeeds, there are no carriage returns. A hex
editor shows each line to be 9 characters long (including 0x0A, the
linefeed).
Am I using the correct matching syntax, and does Perl perform some
translation on $_, that I'm not understanding? Does Perl count the record
separator, or something?
Thanks for any ideas,
Eric
PS: I'm running Perl v5.005_03, Linux kv 2.2.13
------------------------------
Date: Sun, 06 Aug 2000 02:17:55 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Problem w/anchored match
Message-Id: <7a1z03dtex.fsf@merlin.hyperchip.com>
"Eric Adamson" <adamsone@voyager.net> writes:
> I'm processing a text file, and wish to identify lines that contain phone
> numbers. For the moment, I'm testing my routine by just printing them out.
> I wish to find lines matching ###-####, with no other text appearing on the
> line. Why doesn't the following work?
It works fine for me. Perhaps there is something else on the line that
you don't see. Try the following:
foreah $char (split //) {
print "Char -->$char<--\n";
}
for each of the lines you read. This will print the characters one by
one, so that you can examine them. Perhaps there is a space at the
beginning of the line?
--Ala
------------------------------
Date: Sun, 06 Aug 2000 02:40:44 GMT
From: kumar1@home.com (Prasanth A. Kumar)
Subject: Re: Problem w/anchored match
Message-Id: <m3ya2b3ydw.fsf@C654771-a.frmt1.sfba.home.com>
"Eric Adamson" <adamsone@voyager.net> writes:
> I'm processing a text file, and wish to identify lines that contain phone
> numbers. For the moment, I'm testing my routine by just printing them out.
> I wish to find lines matching ###-####, with no other text appearing on the
> line. Why doesn't the following work?
>
> SAMPLE INPUT DATA:
>
> 555-3494
> 555-3949
> 448-3944 Bob Smith
>
> MY SCRIPT:
>
> #!/usr/bin/perl
>
> open(IN, "<testfile.txt");
>
> while (<IN>) {
> if (/^\d\d\d-\d\d\d\d$/) {
> print $_;
> }
> }
>
> close IN;
>
> I tried removing the anchors, and testing for a second condition -- that the
> line have length=8 -- and *still* get no matches! Perl returns a length of
> 10 for the lines that I'm interested in -- chomping only takes it down to 9.
> Lines are broken with linefeeds, there are no carriage returns. A hex
> editor shows each line to be 9 characters long (including 0x0A, the
> linefeed).
<snip>
What about /^\d\d\d-\d\d\d\d.*$/ which will match anything starting
with a phone number followed by optional name or other stuff. You can
also shorten that down to /^\d{3}-\d{4}.*$/ if you like. BTW, the way
I tested this is using perl in interactive mode as 'perl -de 0' and
then you can try most any perl commands out interactively.
--
Prasanth Kumar
kumar1@home.com
------------------------------
Date: Sat, 5 Aug 2000 23:16:48 -0400
From: waltman@netaxs.com (Walt Mankowski)
Subject: Re: Someone please explain the 'my' declaration.
Message-Id: <slrn8opm50.1eu.waltman@netaxs.com>
On Sat, 05 Aug 2000 14:50:55 GMT, sjs@yorku.ca <sjs@yorku.ca> wrote:
>Have you read the explanation in perlfaq7? It seems pretty clear to me.
>
>perldoc -q lexical will find it.
You might also want to read Mark-Jason Dominus' article "Coping With
Scoping". It originally appeared in The Perl Journal, and is available
online at http://www.plover.com/~mjd/perl/FAQs/Namespaces.html
Walt
------------------------------
Date: Sat, 05 Aug 2000 22:07:12 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Stumped Again!
Message-Id: <x7zomr1hww.fsf@home.sysarch.com>
>>>>> "PH" == Pete Holsberg <pjh@mccc.edu> writes:
PH> This should be SOOO easy, but I just can't get it,
PH> I have a file that looks like this (SSNs and phone numers are bogus):
PH> 1 143-80-0908 BARGER-FOX, PAT BOB 04/08/00
PH> 2 140-65-0756 FORD DOG, B J 06/23/00
PH> 3 138-99-9890 BENJAMIN JR, EMILY 04/06/00
PH> 5 124-58-0237 BROCK III, DANA M 03/29/00
PH> 6 220-66-2813 BURRELL, DORETHA M 04/07/00
PH> I want to produce two values for each line, as follows
PH> BARGERFOX and PAT
PH> FORDDOG and B
PH> BENJAMIN and EMILY
PH> BROCK and DANA
PH> BURRELL and DORETHA
PH> but I just can't get the right regular expressions. Can
PH> someone please take pity and send me some suggsted ones?
you have to be clearer. why is JR and III dropped and not DOG? that is a
heuristic you haven't specified except by a limited example. and given
that restriction a simple regex won't do. here is a simple one to just
get the strings out and then you can chop off suffixes:
if ( /([A-Z -]+,\s([A-Z]+)/ ) {
$last = $1 ;
$first = $2 ;
# get rid of dashes
$last =~ tr/-//d ;
# get rid of some suffixes
$last =~ s/\s+III$// ;
$last =~ s/\s+JR$// ;
print "last $last, first $first\n" ;
}
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 05 Aug 2000 22:49:43 GMT
From: Vinny Murphy <VincentMurphy@mediaone.net>
Subject: Re: Stumped Again!
Message-Id: <m2r984htoj.fsf@newton.athome.net>
>>>>> "Pete" == Pete Holsberg <pjh@mccc.edu> writes:
Pete> This should be SOOO easy, but I just can't get it,
Pete> I have a file that looks like this (SSNs and phone numers are bogus):
Pete> 1 143-80-0908 BARGER-FOX, PAT BOB 04/08/00 (609) 466-1821 YES
Pete> 2 140-65-0756 FORD DOG, B J 06/23/00 (609) 587-2726 YES
Pete> 3 138-99-9890 BENJAMIN JR, EMILY 04/06/00 (609) 799-8130 YES
Pete> 5 124-58-0237 BROCK III, DANA M 03/29/00 (609) 371-5073 YES
Pete> 6 220-66-2813 BURRELL, DORETHA M 04/07/00 (609) 530-0308 YES
Pete> I want to produce two values for each line, as follows
Pete> BARGERFOX and PAT
Pete> FORDDOG and B
Pete> BENJAMIN and EMILY
Pete> BROCK and DANA
Pete> BURRELL and DORETHA
Pete> but I just can't get the right regular expressions. Can
Pete> someone please take pity and send me some suggsted ones?
#!/usr/local/ActivePerl-5.6/bin/perl -w
use strict;
while ( <DATA> ) {
print mangle_name($1), "\n"
if m !^\d+\s+\d\d\d-\d\d-\d\d\d\d\s+(.+)\s+\d\d/\d\d/\d\d!;
}
sub mangle_name {
my( $ln, $fn ) = split(',', shift,2); # split on first comma.
$ln =~ s/\b(?:(JR|SR|III?))\b//; # strip out JR, SR, II and III.
$ln =~ s/\W//; # strip out non-words
my $first = $1 if $fn =~ /^\s*(\w+)/; # grab first word.
"$ln and $first"; # return the mangled name
}
__DATA__
1 143-80-0908 BARGER-FOX, PAT BOB 04/08/00 (609) 466-1821 YES
2 140-65-0756 FORD DOG, B J 06/23/00 (609) 587-2726 YES
3 138-99-9890 BENJAMIN JR, EMILY 04/06/00 (609) 799-8130 YES
5 124-58-0237 BROCK III, DANA M 03/29/00 (609) 371-5073 YES
6 220-66-2813 BURRELL, DORETHA M 04/07/00 (609) 530-0308 YES
HTH
Vinny
------------------------------
Date: 05 Aug 2000 19:37:05 -0400
From: David Meyers <dmeyers@panix.com>
Subject: Re: Stumped Again!
Message-Id: <yobya2b5lge.fsf@panix2.panix.com>
pjh@mccc.edu (Pete Holsberg) writes:
> I have a file that looks like this (SSNs and phone numers are bogus):
> 1 143-80-0908 BARGER-FOX, PAT BOB 04/08/00 (609) 466-1821 YES
> I want to produce two values for each line, as follows
> BARGERFOX and PAT
#!/usr/local/bin/perl -w
use strict;
while (<DATA>) {
my $name = substr $_, 17, 20; # Careful with these column numbers
my ($last, $first) = split(/, /,$name); # leaves crappy
# whitespace at end of $first
print "$last and $first\n";
}
__DATA__
1 143-80-0908 BARGER-FOX, PAT BOB 04/08/00 (609) 466-1821 YES
2 140-65-0756 FORD DOG, B J 06/23/00 (609) 587-2726 YES
3 138-99-9890 BENJAMIN JR, EMILY 04/06/00 (609) 799-8130 YES
5 124-58-0237 BROCK III, DANA M 03/29/00 (609) 371-5073 YES
6 220-66-2813 BURRELL, DORETHA M 04/07/00 (609) 530-0308 YES
generates:
BARGER-FOX and PAT BOB
FORD DOG and B J
BENJAMIN JR and EMILY
BROCK III and DANA M
BURRELL and DORETHA M
------------------------------
Date: Sat, 05 Aug 2000 17:04:44 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Stumped Again!
Message-Id: <398CAB9C.48265835@stomp.stomp.tokyo>
Pete Holsberg wrote:
> I have a file that looks like this...:
> 1 143-80-0908 BARGER-FOX, PAT BOB 04/08/00 (609) 466-1821 YES
(snipped data base)
There is a serious logical error with your data base.
Names lie from position 16 through position 32, inclusive,
counting from zero as first position. Any name too long
to fit within this format block, would have to be truncated
leading to a loss of critical data, namely a name.
Consider moving your names to last position and allot
more than enough format spaces to account for long names.
This would also benefit you by only needing to substring
the tail end of your data base, from a preset position
number to grab your names. Character delimit your names
with no spaces included, such as comma delimited. This
sets you up for an easy split based on commas to grab any
combination of names. Adjective modifiers such as Senior,
Junior, First, Second, Third, Esquire, should be last item
for your name block so they can easily be disgarded. Removal
of a hyphen from a woman's hyphenated name, creates a false
name, creates an error.
You display some initials. How do you know if those are
two initials for one person, or single initials for two
people? Seems a bug in the making.
Another logical error is three leading spaces, seven
spaces between your date and telephone number and two
spaces between your phone number and "YES" as shown.
This bloats your data base size by ten characters for each
line of your data base. One-hundred lines; one kilobyte
of wasted storage space. Consider no leading spaces and
one space between items.
A method I would use based on your givens, is to substring
from position 16 and grab 16 characters, if I counted correctly,
then simple regexes will do the rest.
> but I just can't get the right regular expressions. Can
> someone please take pity and send me some suggsted ones?
Post what you have done so far in line of codes. Perhaps you
only need some simple suggestions.
Godzilla!
------------------------------
Date: Sat, 05 Aug 2000 15:20:07 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Tag attributes
Message-Id: <398C9317.8AED505@stomp.stomp.tokyo>
beaumontsystems wrote:
> "Godzilla! wrote:
> > beaumontsystems wrote:
> > > Say I have an HTML-like tag of the form...
> > > <aaa bbb="XyZ" Cc=3>qWerty</aaa>
> > > I'm trying to write a small (Perl) routine which converts:
> > > 1. The tag types (aaa) to upper (or lower) case.
> > > 2. The attribute types (bbb, Cc) to upper (or lower) case
> > > I've achieved 1, but not 2. Can anyone help ?
> > Why? A browser doesn't care if html tags are
> > upper case or lower case or mixed. Only counts
> > in an URL path and perhaps a few other very
> > specific tag types. Why fix it if it ain't broke?
> Yes, I *know* the browser doesnt' care, but we have a client who
> is paying us loads of money to churn out pages, and I happen to think
> they look neater and a wee bit more "professional" if we adopt a
> consistent style. No big deal.
This is even more confusing. You state you and others
are writing documents for a client. Previously, you
stated you need to correct what appears to be some
non-fatal errors in html documents, this is, upper
case or lower case some tags, with quite an odd mix.
So, you boys are writing these documents. Why are
you writing these documents incorrectly? I do not
understand why you do not use a consistent method,
write them correctly initially and not put yourself
in a position of having to go back and correct.
If your co-workers are writing html documents using
this style you exemplified in your initiating article,
why has not their employment been terminated for clear
gross incompetency?
This perhaps is a little harsh. I would make those
who write documents like this, come to my office,
sit down, and correct every single document they
produced like this, sans any pay. If this is not
done, I would then fire them.
Why don't you simply upper case everything except
href URL links and do those by hand? However, if
your URL links work, no change is needed, right?
* moderately amused by this boy *
Godzilla! \u U
------------------------------
Date: Sat, 05 Aug 2000 21:53:57 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Tag attributes
Message-Id: <398c8c09.75331973@news.newsguy.com>
"beaumontsystems" <beaumontsystems@netscapeonline.co.uk> wrote:
>Yes, I *know* the browser doesnt' care, but we have a client who
>is paying us loads of money to churn out pages, and I happen to think
>they look neater and a wee bit more "professional" if we adopt a
>consistent style. No big deal.
You may want to look into HTML Tidy. It's not Perl, but it does
what you want to do as well as other things you're likely to
want to do (see http://www.w3.org/People/Raggett/tidy/).
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Sun, 06 Aug 2000 02:06:34 GMT
From: monty hindman <montyh@defender.gpcc.itd.umich.edu>
Subject: Re: Win32::OLE and MS Excel Problem
Message-Id: <KK3j5.1686$ks4.33760@news.itd.umich.edu>
The Ancient <mikelm@ameritech.net> wrote:
> I need to sort columns in Microsoft Excel using Win32::OLE
> Perl compiles the code OK but Excel throws this exception:
> OLE exception from "Microsoft Excel":
> Unable to get the Sort property of the Range class
> Win32::OLE(0.13) error 0x80020009: "Exception occurred"
> in METHOD/PROPERTYGET "Sort" at xl.pl line 43
> Why does Excel view "Sort" as a property and not a method?
> The code below shows how I setup the worksheet and does
> work until the sort is executed.
> #!perl -w
> use Win32::OLE;
> use Win32::OLE::Const 'Microsoft Excel';
> use strict;
> $ex = Win32::OLE->new('Excel.Application', 'Quit')
> or die "Cannot start Excel";
> $book = $ex->Workbooks->Open("d:\\vb\\test_perl_xl.xls");
> $sheet = $book->Worksheets(1);
> #clear two columns of the sheet
> $sheet->columns("A:B")->Select;
> $ex->Selection->Clear;
> #insert something
> $sheet->Range("A3:B5")->{Value} = [[ 'stuff', 'Xyzzy' ],
> [ 42, 'Perl' ]
> ['more', 'stuff'];
> #size the columns to fit the values inserted
> $sheet->Columns("A:B")->AutoFit;
> #try the sort - This is broken. Can someone offer a hint,
> # solution or resource where I can look this stuff up? I am
> # kind of stumbling around with this.
> #BTW this method works in a VB macro
> $sheet->Range("B3")->Sort ({ Key1 => $sheet->Range("B3"),
> Order1 => xlDescending,
> Key2 => $sheet->Range("A3"),
> Order2 => xlAscending
> });
> $book->Save();
> undef $book;
> undef $ex;
I was unable to replicate the problem. I copied your code, fixed two
syntax errors where you insert the data values, and ran the code without a
hitch.
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
use strict;
my ($ex,$book,$sheet);
$ex = Win32::OLE->new('Excel.Application', 'Quit')
or die "Cannot start Excel";
# I changed the path here.
$book = $ex->Workbooks->Open("c:\\000 Docs\\Perl Stuff\\test.xls");
$sheet = $book->Worksheets(1);
#clear two columns of the sheet
$sheet->columns("A:B")->Select;
$ex->Selection->Clear;
#insert something
# You had syntax errors here, but that wasn't the problem
# you were asking about. Also, I added some more
# values to make sure the sorting was working.
$sheet->Range("A3:B9")->{Value} = [
[ 'a', 'd' ],
[ 9, 1 ],
[ 9, 2 ],
[ 9, 3 ],
[ 1, 'a' ],
[ 1, 'b' ],
[ 1, 'c' ],
];
#try the sort - This is broken. Can someone offer a hint,
# solution or resource where I can look this stuff up? I am
# kind of stumbling around with this.
#BTW this method works in a VB macro
$sheet->Range("B3")->Sort ({ Key1 => $sheet->Range("B3"),
Order1 => xlDescending,
Key2 => $sheet->Range("A3"),
Order2 => xlAscending
});
$book->Save();
undef $book;
undef $ex;
It works fine for me. Here's the output (ascending on column A,
descending on B).
a d
1 c
1 b
1 a
9 3
9 2
9 1
I'm running this on Excel 97 (with SR2) and my perl is:
This is perl, version 5.005_03 built for MSWin32-x86-object
Binary build 522 provided by ActiveState Tool Corp.
--
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3925
**************************************