[12137] in Perl-Users-Digest
Perl-Users Digest, Issue: 5737 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 20 20:07:22 1999
Date: Thu, 20 May 99 17:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 20 May 1999 Volume: 8 Number: 5737
Today's topics:
Re: A basic question about passing parameters on the co (Tad McClellan)
Re: A few questions about Perl 5 <cassell@mail.cor.epa.gov>
Re: A few questions about Perl 5 (Bob Trieger)
Re: A few questions about Perl 5 (Tad McClellan)
Re: autodecrement (Larry Rosler)
Can't use string as a hash ref... (Daniel Parish)
Re: conditional regexp matching. Please advise. <ravik@cyrix.com>
Re: conditional regexp matching. Please advise. <ravik@cyrix.com>
Re: conditional regexp matching. Please advise. (Ilya Zakharevich)
constants question <jhilgedi@indiana.edu>
Re: Extracting form fields (Jen)
Forking and sleeping. ppith@my-dejanews.com
Formatting dates (Jen)
Re: Formatting dates <cassell@mail.cor.epa.gov>
Frozen objs not thawing on flipside of IPC. <bwaite@uswest.com>
Re: HELP:Directory or File exists?? <nbarney@csd.sdl.usu.edu>
Merge MS Word documents (David Beckley)
Re: MS WORD97 Macro Question <camerond@mail.uca.edu>
Re: Parsing email headers.. <*@qz.to>
Re: Parsing email headers.. (Larry Rosler)
Re: Perl Unicode/Multibyte Support (Ilya Zakharevich)
Re: Perl Unicode/Multibyte Support (Larry Rosler)
Sorting a Multi-dimensional array by specific element <david.lindsay@columbian.com>
Re: Sorting a Multi-dimensional array by specific eleme (Larry Rosler)
Win32 Build Vs. Unix Build!!! <wassimk@iname.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 20 May 1999 12:42:48 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: A basic question about passing parameters on the command line.
Message-Id: <82e1i7.h4e.ln@magna.metronet.com>
G. Scott Guillot (gsguillot@demandsolutions.com) wrote:
: 'lo everyone. Basic question about passing parameters to a perl script via
: the command line.
You don't have a Perl question there.
Perl takes whatever args are provided by the shell that
invoked perl.
You have a shell/command interpreter question.
Try using single quotes instead of double quotes.
If that doesn't work, then ask somewhere connected to whatever
shell you are using.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 20 May 1999 15:09:09 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: Anthony Lalande <tonyboy@earthling.net>
Subject: Re: A few questions about Perl 5
Message-Id: <37448805.ECB371EA@mail.cor.epa.gov>
Anthony Lalande wrote:
>
> Greetings.
Hi.
> I'm relatively new at scripting, and probalby don't have all the best
Do you mean you're relatively new at writing CGI scripts?
Or do you mean that you're new at programming in Perl?
As you probably know, there is a major difference between
CGI (which is just a protocol) and the Perl programming
language (which is used for many things besides webwork).
> methods, since I've learned almost completely by imitation and examples.
This can be good.. or bad. If you've learned Perl by studying
the programming examples of Randal Schwartz, then you're
in good shape. If you've learned Perl by studying some of
Matt's Script Archive, then you're probably not.
> I have a few questions. If you could provide an answer, I would _greatly_
> appreciate it if you could forward the answer directly to me (and if you
> want), post the answer to the newsgroup as well.
>
> My questions:
>
> 1- I have a text file with many entries (in order) separated by returns. I
> would like to create an array, using a command like:
>
> @array = sort(<FILE>);
>
> However, I don't want the sorting effects of the sort command, just the
> delimiting effects. I've tried lines like the following:
You seem to have a few problems concerning how Perl works.
sort() is a function, not a command. And it doesn't have
'delimiting effects'. It does, however, impart what in Perl
is called 'list context'. It tells its operand that it should
act like a list instead of a scalar (a single value).
But having '@array' there on the left will do the same thing:
@array = <FILE>; # slurps all lines into @array
$scalar = <FILE>; # reads the next line into $scalar
See the difference? The compiler is smart enough to see
what you want and act accordingly.
> @array = split(/\n/,<FILE>); or
That's not going to do what you think. Did you try it
on a test file and print out the results?
> @array = split(/\r/,<FILE>);
Ooh. Now you're really getting into trouble. Perl is
smart enough to handle newlines the way it ought to for
your stated OS. If you're on a win32 box, it treats the
standard CR/LF combo as \n, the newline. If you're on
some version of unix, it uses the correct single char
as the newline. And ditto for the Mac. You probably
don't want to do the above.
> ... but none of these seem to work.
Not a problem. I gave you a much simpler version which
does. See above.
But you might want to spend a little time reading the
docs that come with Perl. If you don't know how to access
them, check out this URL:
http://www.perlmonth.com/articles//rtfm.html
The Perl docs cover everything. We're talking *hundreds*
of pages of up-to-date info without the glaring errors
of a lot of freely-available Perl code that gets used for
CGI scripts. You might also consider shelling out a
few bucks for the 'llama' book, "Learning Perl" from
O'Reilly.
> 2- This one is a little more web-oriented. Is there any way to pass
> arguments through Server-Side Includes?
Yes. There's even a tutorial or three on SSI if you go to
http://www.cgi-resources.com/
There are some Perl tutorials there too, but not all of them
are correct all of the time.
> 3- Supposing I have a variable: $temporary and the string "button". How
> could I merge the two into a printable string:
>
> print "$temporary\button";
>
> This will interpret the b as a control-character. How could I just use a
> null character to delimit the end of the variable name and the beginning of
> the string character?
Actually, in Perl TMTOWTDI (There's More Than One Way To Do It).
You could just append your string to the variable first, then
print it:
$temporary = $temporary . 'button'; # here '.' is an operator
$temporary .= 'button'; # same thing, but more Perlish
Or you could just use the fact that print() expects a list of
things to print:
print $temporary,'button';
And Perl has a host of functions that will do nifty stuff
with strings. All the docs are available on your system with
your Perl install. You might want to start by looking at
the FAQ (Frequently Asked Questions) and seeing if there's
already an answer waiting for you.
Since you didn't munge your address, you should get an e-mail
from gnat (his bot, actually) with a host of good Perl advice.
Be sure to read through it, and use the suggestions there.
You'll be glad you did.
> Thanks a lot,
You're welcome a lot,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 20 May 1999 22:25:01 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: A few questions about Perl 5
Message-Id: <7i20m3$7mf$1@ash.prod.itd.earthlink.net>
[ courtesy cc sent by mail if address not munged ]
"Anthony Lalande" <tonyboy@earthling.net> wrote:
>Greetings.
>
>I'm relatively new at scripting, and probalby don't have all the best
>methods, since I've learned almost completely by imitation and examples.
Do youself a favor and spend the $25 or so on "Learning Perl".
>I have a few questions. If you could provide an answer, I would _greatly_
>appreciate it if you could forward the answer directly to me (and if you
>want), post the answer to the newsgroup as well.
>
>My questions:
>
>1- I have a text file with many entries (in order) separated by returns. I
>would like to create an array, using a command like:
>
>@array = sort(<FILE>);
>
>However, I don't want the sorting effects of the sort command, just the
>delimiting effects. I've tried lines like the following:
>
>@array = split(/\n/,<FILE>); or
>@array = split(/\r/,<FILE>);
>
You're gonna kick yourself.
@array = <FILE>;
>2- This one is a little more web-oriented. Is there any way to pass
>arguments through Server-Side Includes?
try news:comp.infosystems.www.authoring,cgi with this one.
>3- Supposing I have a variable: $temporary and the string "button". How
>could I merge the two into a printable string:
>
>print "$temporary\button";
print $temporary . 'button';
or
print "${temporary}button";
HTH,
------------------------------
Date: Thu, 20 May 1999 13:13:21 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: A few questions about Perl 5
Message-Id: <hrf1i7.58e.ln@magna.metronet.com>
[ mailed and posted ]
Anthony Lalande (tonyboy@earthling.net) wrote:
: I have a few questions. If you could provide an answer, I would _greatly_
: appreciate it if you could forward the answer directly to me (and if you
: want), post the answer to the newsgroup as well.
: My questions:
: 1- I have a text file with many entries (in order) separated by returns. I
: would like to create an array, using a command like:
: @array = sort(<FILE>);
: However, I don't want the sorting effects of the sort command, just the
: delimiting effects. I've tried lines like the following:
: @array = split(/\n/,<FILE>); or
: @array = split(/\r/,<FILE>);
: .... but none of these seem to work.
You haven't clearly stated what it is that you want.
I think you want each line in an element of the array, with
the newline stripped from the end.
Is that it? If so, then:
chomp(@array = <FILE>);
Or, read them all in, and remove the newline yourself:
@array = <FILE>;
foreach (@array) {chomp}
: 2- This one is a little more web-oriented. Is there any way to pass
: arguments through Server-Side Includes?
It is completely web-oriented.
Please ask that question in a newsgroup that is connected to
the WWW in some way. This is not one of those newsgroups.
: 3- Supposing I have a variable: $temporary and the string "button". How
: could I merge the two into a printable string:
: print "$temporary\button";
: This will interpret the b as a control-character. How could I just use a
: null character to delimit the end of the variable name and the beginning of
: the string character?
print "${temporary}button";
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 20 May 1999 14:50:16 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: autodecrement
Message-Id: <MPG.11ae2376d549ff7989ad2@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7i1v61$je5$1@nnrp1.deja.com> on Thu, 20 May 1999 21:34:56
GMT, tbsmith@deltacom.net <tbsmith@deltacom.net> says...
> Why was it decided that Perl's autodecrement operator would not be
> magical?
Whoever figured out that there was no way to implement it with
consistent semantics. Undoubtedly it was The Other Larry (Wall).
Look in DejaNews for a discussion of this very issue a few weeks ago.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 May 1999 15:32:44 -0700
From: danielp@best.com (Daniel Parish)
Subject: Can't use string as a hash ref...
Message-Id: <7i22ic$2k9$1@shell13.ba.best.com>
The following bit works (it's part of a much larger script that also
works), but it dies with a fatal error with 'use strict':
'Can't use string ("nk2.2-1.17-RA") as a HASH ref while
"strict refs" in use at test.pl line 16, <FITFILE> chunk 1.'
I've looked at 'Tie::RefHash', but I can't claim to understand its
usage in this context. Would someone please be so kind as to point
me at the 'proper' construct with which to replace
'$$i{$ro} = $fitvalue;'?
Thanks in advance.
Daniel
<danielp@best.com>
#!/usr/sbin/perl -w
use strict;
my ($i, $ro, $fitvalue, $thisline);
my @filelist = qw( nk2.2-1.17-RA nk2.2-1.04-RA nk2.2-1.17-A
nk2.2-1.17-RA nk2.2-1.18-A nk2.2-1.18-RA
nk2.2-1.26-A nk2.2-1.26-RA );
foreach $i (@filelist) {
open (FITFILE, "$i-BWL.rofit")
|| die "Could not open file $i-BWL.rofit; $!";
while ( $thisline = <FITFILE> ) {
chomp $thisline;
($ro, $fitvalue) = split(" ", $thisline);
$$i{$ro} = $fitvalue;
}
close FITFILE;
}
------------------------------
Date: Thu, 20 May 1999 17:15:59 -0500
From: Ravi Kumar <ravik@cyrix.com>
Subject: Re: conditional regexp matching. Please advise.
Message-Id: <3744899F.7B49DCC8@cyrix.com>
Bart Lateur wrote:
> Ravi Kumar wrote:
> [...]
> Well stop trying. Get rid of them afterwards.
[...]
> Bart.
Well, OK, if there is no other way, I'll do it like you showed. But it would
be nice to have regexp capability which does this.
region1-region2-region3
The rule is
capture region2 if region1 exists OR region2 exists BUT !(region1 AND region2)
--
Cheers,
--ravi
------------------------------
Date: Thu, 20 May 1999 17:21:51 -0500
From: Ravi Kumar <ravik@cyrix.com>
Subject: Re: conditional regexp matching. Please advise.
Message-Id: <37448AFF.97CB82D0@cyrix.com>
> [...]
> > What I am trying to avoid is verifying the fields $1 to $4
> > seperately after extracting from the original sentence.
>
> Yuk. Here is a 'one-liner' that captures each of the values (looking
> for a word followed by a hex number):
>
> #!/usr/local/bin/perl -w
> use strict;
>
> $_ = 'set addr 0x10000 data deadbeefh bytes 0xff expect bab009h';
> my @values = map hex, grep defined,
> /\w\s+ (?: 0x([0-9A-F]+) | ([0-9A-F]+)h ) \b/gix;
>
> print "@values\n" if @values == 4; # Here is the verification!
This does not check for, say 'reset' instead of 'set'. There is a grammar
associatedwith the structure of the sentences. I don't want to complicate my
query, but my
question can be thus rephrased (also in another reply)
given a string of substance ...
region1-region2-region3
find a regexp rule like so
capture region2 iff (region1 OR region2) AND !(region1 AND region2)
--
Cheers,
--ravi, (ravik,8643)
------------------------------
Date: 20 May 1999 23:12:10 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: conditional regexp matching. Please advise.
Message-Id: <7i24sa$svs$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Ravi Kumar
<ravik@cyrix.com>],
who wrote in article <3744899F.7B49DCC8@cyrix.com>:
> > Well stop trying. Get rid of them afterwards.
> Well, OK, if there is no other way, I'll do it like you showed. But it would
> be nice to have regexp capability which does this.
>
> region1-region2-region3
>
> The rule is
> capture region2 if region1 exists OR region2 exists BUT !(region1 AND region2)
Perusing Perl docs will show that there is such a possibility.
Ilya
------------------------------
Date: Thu, 20 May 1999 18:17:47 -0500
From: "John Hilgedick" <jhilgedi@indiana.edu>
Subject: constants question
Message-Id: <7i24nu$7kt$1@jetsam.uits.indiana.edu>
There are a number of places in my code where I'd like to use constants that
are declared in a separate file (similar to constants that are included in
header files in the c/c++ world). How can I do this in perl? Do I have to
use a module to do this? Doesn't perl provide this? I haven't been able to
find the answer to this anywhere? Is there a perl stud out there who can
help?
Any light you can shed would be greatly appreciated!
-john
------------------------------
Date: Thu, 20 May 1999 22:09:17 GMT
From: jenmei@my-dejanews.com (Jen)
Subject: Re: Extracting form fields
Message-Id: <37448897.71816957@client.nw.news.psi.net>
No, I want to use Perl for Web automation. Basically, we have a server
that goes down ever once in a while, and I want to write a script that
connects to it, logins, and does a simple look up -- just to check
that the Web server, the app. server, and the database server are all
working.
Just a simple get for the first page, change some form fields, then a
post, change some form fields, then another post. Real easy stuff.
I'd then schedule the script to run every 15 minutes -- if the servers
are not up, the script would restart services, reboot machines, etc.,
and send a page to the support staff. I've currently written the Web
automation piece in Cold Fusion and the rest of the stuff in Perl. I'd
like to rewrite the CF part and have the whole thing in Perl.
I'll check out the modules -- was hoping for a quick tip, but I guess
I'll just have to dig in.
Thanks!
Jen
On Tue, 18 May 1999 10:41:54 -0400, "Stephen Warren"
<swarren@www.wwwdotorg.org> wrote:
><jenmei@my-dejanews.com> wrote in message
>news:7hr82b$see$1@nnrp1.deja.com...
>> Is there an easy way to extract form fields using Perl?
>
>You might try the CGI module:
>
>use CGI ;
>
>> I'm just
>> looking for a quick way to automate logging into a Web page (all HTML,
>> no password dialogs) and submitting a few forms. I was hoping someone
>> may have written something that would make this easier.
>
>It sounds like you're trying to use HTML forms for security. Re-inventing
>the wheel may not be the most secure thing in the world...
>
>Perhaps you should go to the comp.infosystems.www.authoring.cgi newsgroup
>and read their FAQ - some of the answers you want are probably there, since
>this newsgroup doesn't really have anything to do with CGI specifically
>(although you could use Perl to write your CGI scripts)
>
>--
>Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
>mailto:swarren@techhouse.com http://www.techhouse.com/
>mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
> MIME, S/MIME and HTML mail are acceptable
>
>
>
------------------------------
Date: Thu, 20 May 1999 23:12:41 GMT
From: ppith@my-dejanews.com
Subject: Forking and sleeping.
Message-Id: <7i24t7$nem$1@nnrp1.deja.com>
Hello. It's been a while since I've asked for help here, but
you guys have never let me down. Here's my problem:
I currently have a perl program running in a crontab every
fifteen minutes all the time. It depends on webservers
being "up" to function. If a webserver is hanging, my program
will know because I create a lock file when the program
starts, and I delete it right before it ends. This is not
good enough. If a webserver hangs (for any reason), my
program (what does it do? generates an image on the fly
using GDI.pm of disk usage statistics for serveral servers...
thought you might ask) will not run until the webserver is
fixed and the lock file is removed. This prevents the server
running my program from hanging. Anyways, I was wondering if
Perl could fork off the call to a webserver and sleep for
ten seconds while waiting for the data. When my program
wakes up, if the data has still not arrived, I want to kill
the (child?) process trying to receive the data and move on
to another webserver. I already have it so it e-mails the
administrator once a day if a webserver is hanging...but the data graphs
must be generated despite how many webservers (usually 0) are hanging.
I have read Perl's documentation on fork and Perl Interprocess
Communication. The only thing I got out of those was a way to time my
program and kill it after so many seconds. I don't want to time my
program...I want to time a function call that can be killed if it
takes too long to run. Please help if this is not too complicated
for you.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Thu, 20 May 1999 22:15:40 GMT
From: jenmei@my-dejanews.com (Jen)
Subject: Formatting dates
Message-Id: <37448a56.72264230@client.nw.news.psi.net>
Is there an easy way to do this? I've read about the existence of a
Date::Format module, but have not been able to find it anywhere. I can
write my own, but it just sounds like this is something someone has
already done.
Thanks!
Jen
------------------------------
Date: Thu, 20 May 1999 16:49:45 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Formatting dates
Message-Id: <37449F99.C1D1A5CB@mail.cor.epa.gov>
Jen wrote:
>
> Is there an easy way to do this? I've read about the existence of a
> Date::Format module, but have not been able to find it anywhere. I can
> write my own, but it just sounds like this is something someone has
> already done.
You should be able to find it at CPAN. If your version of Perl
is recent enough, you ought to find it installed on your system.
Try typing this at a command prompt and see if you get a manpage:
perldoc Date::Format
Graham Barr wrote it (along with a number of other nifty
modules), so you'll want to snag it rather than rolling your
own.
> Thanks!
You're welcome,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 20 May 1999 16:01:00 -0600
From: Brad Waite <bwaite@uswest.com>
Subject: Frozen objs not thawing on flipside of IPC.
Message-Id: <3744861C.15CB93D6@uswest.com>
Tom Christiansen wrote:
> How do I keep persistent data across program calls?
>
> For some specific applications, you can use one of the DBM modules.
> See the AnyDBM_File manpage. More generically, you should consult
> the FreezeThaw, Storable, or Class::Eroot modules from CPAN. Here's
> one example using Storable's `store' and `retrieve' functions:
>
> use Storable;
> store(\%hash, "filename");
>
> # later on...
> $href = retrieve("filename"); # by ref
> %hash = %{ retrieve("filename") }; # direct to hash
>
I guess I need a little more hand-holding.
I've tried to use Storeable, FreezeThaw and Eroot all with no luck whatsoever.
If I freeze an object and then thaw it in the same program, everything's fine.
When I store it using IPC::ShareLite, and then fetch it in another program, I
dump core. Here's some snippets:
# Program 1
use GD;
use IPC::ShareLite;
$share = new IPC::ShareLite( -key=>'Joe', -create=>1, -destroy=>0);
open(GIF, "/tmp/pic.gif");
$pic = newFromGif GD::Image(GIF);
close GIF;
$frozen = freeze($pic);
$share->store($frozen);
# Program 2
use GD;
use IPC::ShareLite;
$share = new IPC::ShareLite( -key=>'Joe', -create=>1, -destroy=>0);
$frozen = $share->fetch;
$pic = thaw($frozen);
print $pic->gif;
Results: seg faults and dumps core.
Every variation I've tried produces the same result. Can anyone see why this
isn't working?
------------------------------
Date: Thu, 20 May 1999 14:15:23 -0600
From: Neal Barney <nbarney@csd.sdl.usu.edu>
Subject: Re: HELP:Directory or File exists??
Message-Id: <37446D5B.969B081A@csd.sdl.usu.edu>
kgentes@gentek.net wrote:
>
> How do I test the existance of a directory or
> file in Perl?
-e is what you are looking for.
.
.
.
$filename = <STDIN>;
chop($filename);
if (-e $filename) {
# do something neat
}
.
.
.
*----------------------------------------------*
Neal J. Barney
Space Dynamics Laboratory/USU
Software Engineering and Networking Group
*----------------------------------------------*
------------------------------
Date: Thu, 20 May 1999 23:07:05 GMT
From: david@bgraphx.com (David Beckley)
Subject: Merge MS Word documents
Message-Id: <374493e6.476435@news.swcp.com>
I am trying to merge a bunch of MS Word 97 documents into a single
document with a Perl program. The program works fine on straight ASCII
text, but balks when it hits the control codes at the front on the
WORD documents. Any hints, please?
Sorry I don't have the program to show you at the moment....
TIA,
David
------------------------------
Date: Thu, 20 May 1999 16:42:32 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
To: Derald Powell <derald_powell@hp.com>
Subject: Re: MS WORD97 Macro Question
Message-Id: <374481C8.60B0C4E7@mail.uca.edu>
[cc'd to dp]
Derald Powell wrote:
>
> After recording a word97 macro, how do you make it availabe for execution by
> a perl script.
> I know this THE perl newsgroup, but I can't find a word newsgroup, nor
> information on accessing
> word scripts. Any help appreceiated. You can send replies to
> cis118instructor@yahoo.com if you like.
> Thanks in advance.
Use Win32::OLE. There is an excellent article on Win32::OLE in TPJ #10.
Also, the docs in the ActiveState distribution are helpful (please use
5.0052\02, build 509 or above, the old 5.003 version isn't supported
now), and peruse the Win32-Users mailing list archives at
www.activestate.com (you might even consider subscribing to the list).
Cameron
--
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu
------------------------------
Date: 20 May 1999 22:13:18 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: Parsing email headers..
Message-Id: <eli$9905201743@qz.little-neck.ny.us>
In comp.lang.perl.misc, Larry Rosler <lr@hpl.hp.com> wrote:
> David Raufeisen <raufeisen@home.com> says...
> > I have "John Doe <jdoe@somewhere.com>" in variable $HEADER{'from'}
> my ($fname, $lname, $email, $user) =
> $HEADER{from} =~ /(\S+)\s+(\S+)\s+<(([^@]+)[^>]+)>/;
#!perl -w
while(<DATA>) {
/^From:\s*(.*)/i or next;
my %HEADER = ( from => $1 );
my ($fname, $lname, $email, $user) =
$HEADER{from} =~ /(\S+)\s+(\S+)\s+<(([^@]+)[^>]+)>/;
printf("First: %-8s; Last: %-7s; User: %-9s; email: %s\n",
$fname, $lname, $user, $email);
}
# Below: a list of from lines from comp.lang.perl.misc. RFC1036
# limits Usenet 'From' headers to be a *subset* of those allowed
# for email. This list makes it painfully clear that the above
# RE 'works' for only a very few cases.
__DATA__
From: Eli the Bearded <*@qz.to>
From: Jonathan Stowe <gellyfish@gellyfish.com>
From: "John S. Ware" <jsware@att.com>
From: Luis Gonzalo Aller Arias <gonzalo@aller.com>
From: TRG Software : Tim Greer <webmaster@chatbase.com>
From: bart.lateur@skynet.be (Bart Lateur)
From: ehpoole@ingress.com (Ethan H. Poole)
From: smnayeem@my-dejanews.com
From: kaih=7H8qT0T1w-B@khms.westfalen.de (Kai Henningsen)
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
From: RayG <rgoldber@eb.com>
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Gives these results:
First: the ; Last: Bearded; User: * ; email: *@qz.to
First: Jonathan; Last: Stowe ; User: gellyfish; email: gellyfish@gellyfish.com
First: S. ; Last: Ware" ; User: jsware ; email: jsware@att.com
First: Aller ; Last: Arias ; User: gonzalo ; email: gonzalo@aller.com
First: Tim ; Last: Greer ; User: webmaster; email: webmaster@chatbase.com
First: ; Last: ; User: ; email:
First: ; Last: ; User: ; email:
First: ; Last: ; User: ; email:
First: ; Last: ; User: ; email:
First: ; Last: ; User: ; email:
First: ; Last: ; User: ; email:
First: ; Last: ; User: ; email:
Plus a lot of 'use of undefined variable' errors.
Parsing 'from' headers properly is very complex. Attempting to get
data such as first and last name out of a from header is futile.
Elijah
------
<URL:http://www.qz.to/eli/faqs/addressing.html#from>
------------------------------
Date: Thu, 20 May 1999 16:02:02 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Parsing email headers..
Message-Id: <MPG.11ae34486c0312a6989ad3@nntp.hpl.hp.com>
In article <eli$9905201743@qz.little-neck.ny.us> on 20 May 1999 22:13:18
GMT, Eli the Bearded <*@qz.to> says...
> In comp.lang.perl.misc, Larry Rosler <lr@hpl.hp.com> wrote:
> > David Raufeisen <raufeisen@home.com> says...
> > > I have "John Doe <jdoe@somewhere.com>" in variable $HEADER{'from'}
> > my ($fname, $lname, $email, $user) =
> > $HEADER{from} =~ /(\S+)\s+(\S+)\s+<(([^@]+)[^>]+)>/;
...
> # Below: a list of from lines from comp.lang.perl.misc. RFC1036
> # limits Usenet 'From' headers to be a *subset* of those allowed
> # for email. This list makes it painfully clear that the above
> # RE 'works' for only a very few cases.
Quite true. But the cases that the above RE 'works' for are the very
ones that follow the template the user provided as an example. Had I
wanted to solve a more general problem, I would have tried harder and,
presumably, done better. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 May 1999 22:25:57 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl Unicode/Multibyte Support
Message-Id: <7i225l$s8q$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to J|rgen Exner
<juex@my-dejanews.com>],
who wrote in article <7i1nve$fi0@news.dns.microsoft.com>:
> > :I am doing research on Perl's Multibyte capabities. I found information
> > :about perllocale, internationalization, localization and so on. We are
> > :trying decide whether to use Java or Perl to handle international
> > :languages to publish to international websites (Japan, Chinese, and
> > :European countries).
> >
> > Did you read this:
> >
> > NAME
> > utf8 - Perl pragma to turn on UTF-8 and Unicode support
>
> Ok, sounds really great to me.
> But what about true Unicode support (i.e. not converted into UTF-8)?
> That's a problem I'm facing right now.
There is no conversion of any kind. Perl strings are just sequences
of small integers. Without `use utf8' small means 0..255. With `use
utf8' small means 0..2**36-1. This is the only difference (forgetting
about speed and bugs).
Ilya
P.S. I think it goes without saying that these small integer may have
some "properties", like being lowercase/uppercase, digits,
whitespace etc. This *is* the UNICODE part of the picture.
------------------------------
Date: Thu, 20 May 1999 16:07:33 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl Unicode/Multibyte Support
Message-Id: <MPG.11ae3594aa131aaf989ad4@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7i225l$s8q$1@mathserv.mps.ohio-state.edu> on 20 May 1999
22:25:57 GMT, Ilya Zakharevich <ilya@math.ohio-state.edu> says...
...
> There is no conversion of any kind. Perl strings are just sequences
> of small integers. Without `use utf8' small means 0..255. With `use
> utf8' small means 0..2**36-1. This is the only difference (forgetting
> about speed and bugs).
0..2**32-1 I hope. Unless you are using some sort of ancient Honeywell
machine, or whatever. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 20 May 1999 15:47:57 -0700
From: David Lindsay <david.lindsay@columbian.com>
Subject: Sorting a Multi-dimensional array by specific element
Message-Id: <3744911D.4A61AA3E@columbian.com>
I've run into a problem trying to sort a multi-dimensional array.
I read a file into the mult-dim array that has lines similar to:
"ADV" "Cash" 1999 "100320000000" 04/01/99 412.3
I want to sort the array by the 2nd element, then the 4th.
To load the array I use:
while (defined ($inrec = <INFILE>))
{
chomp $inrec;
push @gl, [ split ' ', $inrec ];
}
I can access the data by referencing $gl[$x]->[$y], so I know the data
gets loaded. I've researched sorting from both of the Camel books which
mostly talks about sorting one dimensional arrays. I found a possible
way in the Perl Cookbook entry 4.15 page 116. It talks about "Sorting a
List by Computable Field". I have a feeling this is somehow the way to
do it but their example just confuses me.
If anyone can explain a good way to do this I would appreciate it.
Thank you.
David Lindsay
david.lindsay@columbian.com
------------------------------
Date: Thu, 20 May 1999 16:46:57 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting a Multi-dimensional array by specific element
Message-Id: <MPG.11ae3ecd5a0c1412989ad5@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <3744911D.4A61AA3E@columbian.com> on Thu, 20 May 1999
15:47:57 -0700, David Lindsay <david.lindsay@columbian.com> says...
> I've run into a problem trying to sort a multi-dimensional array.
>
> I read a file into the mult-dim array that has lines similar to:
>
> "ADV" "Cash" 1999 "100320000000" 04/01/99 412.3
>
> I want to sort the array by the 2nd element, then the 4th.
>
> To load the array I use:
>
> while (defined ($inrec = <INFILE>))
> {
> chomp $inrec;
> push @gl, [ split ' ', $inrec ];
> }
>
> I can access the data by referencing $gl[$x]->[$y], so I know the data
> gets loaded. I've researched sorting from both of the Camel books which
> mostly talks about sorting one dimensional arrays.
One can sort only a list, which is inherently one-dimensional.
> I found a possible
> way in the Perl Cookbook entry 4.15 page 116. It talks about "Sorting a
> List by Computable Field". I have a feeling this is somehow the way to
> do it but their example just confuses me.
>
> If anyone can explain a good way to do this I would appreciate it.
Rather than explain it, how about I show you a solution, based on the
paradigm in the Cookbook Recipe 4.15 (the Schwartzian Transform), and
let you figure it out from there?
#!/usr/local/bin/perl -w
use strict;
my @gl = map [ split ] => <DATA>;
my @sorted =
map $_->[0] =>
sort { $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2] }
map [ $_, @$_[1, 3] ] =>
@gl;
print map join(' ' => @$_) . "\n" => @sorted;
__END__
"ADV" "Dash" 1999 "100320000001" 04/01/99 412.3
"ADV" "Cash" 1999 "100320000000" 04/01/99 412.3
"ADV" "Dash" 1999 "100320000000" 04/01/99 412.3
It's not clear why you want to create the two-dimensional array at all,
if all you want to do is sort on some of the fields of the data. So...
#!/usr/local/bin/perl -w
use strict;
print
map $_->[0] =>
sort { $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2] }
map [ $_, (split)[1, 3] ] =>
<DATA>;
__END__
"ADV" "Dash" 1999 "100320000001" 04/01/99 412.3
"ADV" "Cash" 1999 "100320000000" 04/01/99 412.3
"ADV" "Dash" 1999 "100320000000" 04/01/99 412.3
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 20 May 1999 17:59:23 -0500
From: "Wassim Metallaoui" <wassimk@iname.com>
Subject: Win32 Build Vs. Unix Build!!!
Message-Id: <374494b2.0@wznews.webzone.net>
Perl Newsgroup Readers,
Is the Win32 build of Perl the same as the normal Unix build... If not what
is left out...
I was told that flock would not work on a windows machine....
I am asking because I am using [Webster Professional]
Please e-mail or CC this reply to wassimk@iname.com if possible..
Thanks,
Wassim
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5737
**************************************