[8196] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1814 Volume: 8

???@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 5 02:14:20 1998

Date: Wed, 4 Feb 98 23:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 4 Feb 1998     Volume: 8 Number: 1814

Today's topics:
    Re: A problem - please help (Martin Vorlaender)
    Re: A regex problem <rjk@coos.dartmouth.edu>
    Re: Can I speed up this code? <rjk@coos.dartmouth.edu>
    Re: can variables be generated on the fly <cdkaiser@delete.these.four.words.concentric.net>
    Re: Change user ID (David Efflandt)
    Re: dir/file attributes (David Efflandt)
    Re: Don't use signal handlers (was Re: Child processes) (Chip Salzenberg)
    Re: eval FAQ???  Hardest part of perl to figure out <joseph@5sigma.com>
    Re: Help Wanted: Parsing data from oddly formatted file <rjk@coos.dartmouth.edu>
    Re: Help! 255-char URL limit passing form values to cgi (David Efflandt)
    Re: How Do I Tell Whether a Key Is Valid for an Associa <rjk@coos.dartmouth.edu>
    Re: html tags <rjk@coos.dartmouth.edu>
    Re: Is file locking necessary? (Iain Chalmers)
    Re: Is Perl 5 year 2000 compliant? (Iain Chalmers)
    Re: Is Perl 5 year 2000 compliant? <Barticus@worldnet.att.spam.net>
    Re: Is this correct? File Locking <ebohlman@netcom.com>
    Re: Is this correct? File Locking <joseph@5sigma.com>
    Re: killing a child process after a timeout <joseph@5sigma.com>
    Re: Mail checker.... (Dave O.)
    Re: Multi-line blocks of text <rjk@coos.dartmouth.edu>
    Re: Optimizing dependency generation <joseph@5sigma.com>
    Re: Optimizing regular expression <joseph@5sigma.com>
    Re: Perl Stock Quote Retriever <rjk@coos.dartmouth.edu>
        PGP5, open3 and cgiwrap (Philip)
    Re: Quickie: regexp for valid e-mail addresses (Abigail)
    Re: split /\s*,\s*/ <joseph@5sigma.com>
    Re: Tie-Dee-Perl (Cleanliness is next to Goodliness, or <ajohnson@gpu.srv.ualberta.ca>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 05 Feb 1998 06:49:09 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: A problem - please help
Message-Id: <34d952d5.524144494f47414741@radiogaga.harz.de>

V. Chandrasekhar (vchandra@mail.delcoelect.com) wrote:
[...trying to use 16 bit signed integers...]

:         if ($data > 0x7fff) { $data = 0xffff0000 + $data; }

: In Case 2, even though I convert the number from ffff to ffffffff,
: perl treats it as a positive number by going to double precision
: (i.e., 00000000ffffffff). Obviously, I need something other than
: $data = 0xffff0000 + $data;
: to convert my negative numbers to real negative numbers.

The perlop POD has a section about integer arithmetic. Put a

use integer;

into your subroutine.

cu,
  Martin
--
                          | Martin Vorlaender | VMS & WNT programmer
 Ceterum censeo           | work: mv@pdv-systeme.de
 Redmondem delendam esse. |       http://www.pdv-systeme.de/users/martinv/
                          | home: martin@radiogaga.harz.de


------------------------------

Date: Thu, 05 Feb 1998 01:22:07 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: A regex problem
Message-Id: <34D95A8F.AFE3C25A@coos.dartmouth.edu>

Peter Kruse wrote:
> 
> how about:
> while(<>) {
>         while(s/(<h3>[^<]*)<p>/$1/gi){}
>         print;
> }
> which assumes that <h3> and </h3> are not separated by newline.

Actually, it doesn't.  [^<] can match a newline.

What it does assume, unfortunately, is that there are no tags
aside from <p> with the <H3>
i.e.:

<H3>This is <b>really</b> important<p>So pay attention</H3>

Chipmunk


------------------------------

Date: Thu, 05 Feb 1998 00:48:58 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Brett Denner <Brett.W.Denner@lmco.com>
Subject: Re: Can I speed up this code?
Message-Id: <34D952CA.F25ADE24@coos.dartmouth.edu>

[posted and mailed]

Brett Denner wrote:
> 
> Does anyone have a faster algorithm to read a text file with numbers in
> several columns and extract certain columns into arrays?
>
> [snip]

The bottleneck here is reading the file.  There's not much you can do to
speed that up.  Reading in the whole file at once might help, but then
again, it might not.

Chipmunk


------------------------------

Date: 5 Feb 1998 05:56:21 GMT
From: Cameron Kaiser <cdkaiser@delete.these.four.words.concentric.net>
Subject: Re: can variables be generated on the fly
Message-Id: <6bbka5$qgc@examiner.concentric.net>

aml@world.std.com (Andrew M. Langmead) writes:

>By the way from you first comment, I can only wonder. Can you find a
>section of "Programming Perl" that talks about symbolic references in
>anything but a discouraging manner?

As I recall, I saw the section, said 'neat!' and used it without reading
the rest of the section. So I re-read the section. Cheers to Larry for
still including a useful feature -- and it is useful for quick hacks --
despite whatever reservations he might have about it, although lots of
people like me will see the feature and ignore the warning :-)

--
Cameron Kaiser
cdkaiser at concentric dot net (it hasn't helped the spam yet though)
*** visit the Spectre Server at www.sserv.com
*** C64 software lives! www.computerworkshops.home.ml.org


------------------------------

Date: Thu, 05 Feb 1998 05:24:33 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Change user ID
Message-Id: <34dc49f2.5441726@flood.xnet.com>

sxv10@po.CWRU.Edu (Saidapet Vishnuraman) wrote:

>
>Hi,
>
>I have a perl script which various users would be running.  In the
>script I want to change the user id to another user before running 
>certain section of the code.  How do I do that in perl?
>
>Any help would be very much appreciated.
>
>Thanks a lot.
>
>V. Raman

You likely need an suid C wrapper that launches the script (since most
systems do not do suid *scripts*).  The perl4 book "Programming perl"
used to have a script to make the wrapper, but the perl5 book does
not.  Make sure that script has the proper path to your cc or gcc.  It
might be on CPAN.

Then see 'man chmod' and read up on suid (set user id), tainted
variables and special variables $<, $>.  On some systems once you
change the id you cannot change it back.


David Efflandt/Elgin, IL USA
efflandt@xnet.com    http://www.xnet.com/~efflandt/


------------------------------

Date: Thu, 05 Feb 1998 05:48:18 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: dir/file attributes
Message-Id: <34de5112.7266118@flood.xnet.com>

Paul Mone <pjmone@symbioticinc.com> wrote:

>I have pages on my web which are secure via a cgi password script
>that I wrote...On these pages users can download certain products which
>I would not want the average user to download.  the problem is that
>anyone can download these files if they type in the complete URL (i.e.
>www.company.com/files/paid/expensiveproduct.zip)
>Is there a way to change file or directory attributes on the fly?  I
>suspect not because they will be user "nobody".  Does anyone have any
>suggestions on how to secure these products and "un-secure" them, when
>approproate, with a perl script?

First put the file where you cannot get to it with a URL and then use
a CGI script to pass it on if authorized.  Whether you can pass on a
proper file name depends upon too many factors unrelated to perl.
Proceed directly to comp.infosystems.www.authoring.cgi.


David Efflandt/Elgin, IL USA
efflandt@xnet.com    http://www.xnet.com/~efflandt/


------------------------------

Date: Thu, 05 Feb 1998 05:03:30 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Don't use signal handlers (was Re: Child processes)
Message-Id: <6bbh9q$1h$1@cyprus.atlantic.net>

According to ilya@math.ohio-state.edu (Ilya Zakharevich):
>My experience shows that the simple loop is safe with gcc (satrting
>from 5.004_02?), hard loop is safe with gcc+voodo-patch.

You know, there's a reason that "it works for me" is not accepted as
proof of correctness.
-- 
Chip Salzenberg               - a.k.a. -                <chip@pobox.com>
        "Nice shooting, Zanthar!"  "Thanks, Denise."  // MST3K
           ->  Ask me about Perl training and consulting  <-
    Like Perl?  Want to help out?  The Perl Institute: www.perl.org


------------------------------

Date: Wed, 04 Feb 1998 23:22:01 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: eval FAQ???  Hardest part of perl to figure out
Message-Id: <34D95A64.460D22CF@5sigma.com>

I can't see any reason why you can't do this with references.
Are you stuck with perl 4 for some reason?!?

	-joseph

Chris Sherman wrote:
> $fred is set to something that looks like "os_$reg->{OSNAME}" (which
> is an entry in a config-like structure) which I then want expand to
> something like "os_hpux", which is then used to dereference another part
> of the config structure.

-- 
Joseph N. Hall, prop., 5 Sigma Productions       mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training  . . . . . . . . . . . . . . .  http://www.perltraining.com


------------------------------

Date: Thu, 05 Feb 1998 01:29:08 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Help Wanted: Parsing data from oddly formatted files
Message-Id: <34D95C34.27B8390B@coos.dartmouth.edu>

Andrew M. Langmead wrote:
> 
>     my ($field,$data) = split /\n/,$_,1; # separate field from data at 1st \n
                                       ^^^
Not particularly useful...

I think you meant:

my ($field,$data) = split /\n/,$_,2;

:-)

Chipmunk


------------------------------

Date: Thu, 05 Feb 1998 04:59:36 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Help! 255-char URL limit passing form values to cgi
Message-Id: <34db4662.4529757@flood.xnet.com>

James Munroe and Tricia O'Neill <eccles@astral.magic.ca> wrote:

>When sending the contents of an HTML form's textarea to a Perl cgi, or a 
>large number of form fields with their associated values to a Perl cgi, 
>anything after the first 255 characters gets truncated, because Netscape's 
>URL line is limited to that size. Is there any other way to communicate 
>form field values from the browser to a cgi, in such a way that the 
>_complete_ string of form names and values is preserved?
>
>Please email your reply to eccles@astral.magic.ca (preferred) or post a 
>reply in this newsgroup. My need is dire, and I would be grateful for any 
>assistance.
>
>Sincerely,
>
>James Munroe

This is not perl related, but you want to use method POST instead of
GET for anything more than a few small fields.  If you don't know how
to receive POST data see my comment script.


David Efflandt/Elgin, IL USA
efflandt@xnet.com    http://www.xnet.com/~efflandt/


------------------------------

Date: Thu, 05 Feb 1998 01:38:25 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: How Do I Tell Whether a Key Is Valid for an Associative Array?
Message-Id: <34D95E61.CEB3E0F@coos.dartmouth.edu>

Vladimir Alexiev wrote:
> 
> Joe Gottman <joegottman@nospam.worldnet.att.net> writes:
> 
> >    $foo{'bar'} = undef();
> undef()? That's a weird way to write the constant undef.
> Either write foo=undef, or undef(foo).

Yeah, it is.  Of course, *there is no 'constant undef'*.
undef is a function.  Otherwise, you wouldn't be able
to write undef(foo), now would you?

Chipmunk


------------------------------

Date: Thu, 05 Feb 1998 00:17:27 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: html tags
Message-Id: <34D94B67.F69CD9A6@coos.dartmouth.edu>

Eric Bohlman wrote:
> 
> Jason Boxman <benefits@cybertechs.com> wrote:
>    ([^<])*?
> #this matches zero or more occurrences of anything other than a left
> #angle-bracket, and stores it in $3.  Note that the matching stops as
> #soon as anything that matches the rest of the expression is found.

Actually, it will only store the *last* character matched by the [^>] in $3.
The quantifier should be inside the parentheses.

Same for the rest of the original poster's regex.

Moving in and out of the capturing parentheses will slow down the regex
engine unnecessarily.

Chipmunk


------------------------------

Date: Thu, 05 Feb 1998 16:25:32 +1100
From: bigiain@mightymedia.com.au (Iain Chalmers)
Subject: Re: Is file locking necessary?
Message-Id: <bigiain-ya02408000R0502981625320001@news.ozemail.com.au>

"Bill Genzer" <bill@fathead.net> wrote:
> 
>I am very new at PERL and I have just started writing my own CGI scripts
>(really editing other scripts).  I have to admit it seems very simple and
>easy to learn.  My question is if it is necessary to lock files before
>reading or writing to files?  If it is necessary, how do you do it?  I've
>seen a few ways other people do it, but it seems very complicated,  I've
>heard of using something called flock?  But not knowing hardly anything
>about PERL I have no Idea how to use it.
>
>I've done a few small tests myself to see what would happen if a user tried
>to update the same file at the same time and I can't seem to get it to mess
>up, Is there some kind of file locking/sharing feature built in to PERL?  Or
>do you have to still do it manually?
>
>Thanks
>-Bill

sometimes... (useful answer - eh?)

if theres any chance of 2 cgi scripts writing to the file at the same time,
and you give a damn about whats in the file (which presumably you do - else
you wouldn't bother making it...) then yes, you need to lock the file.

if there is never going to be more than one program writing to the file, or
the file is only ever read (and never written), then you can ignore it (i
used to write form handling scripts that wrote data to a temporary file,
whos name included the process id of the script, and then mailed the temp
file and deleted it - since there couldn't have been two copies of the
script running under the same process id, i never bothered locking these
files)

you really should check out Randal Schwartz's stuff on his website:

<http://www.stonehenge.com/merlyn>

particularly columns 4 and 5 in his web techniques column - its got a good
explanation of how and why he used locking in those scripts.

cheers

iain

Iain Chalmers
bigiain@mightymedia.com.au


------------------------------

Date: Thu, 05 Feb 1998 16:03:09 +1100
From: bigiain@mightymedia.com.au (Iain Chalmers)
Subject: Re: Is Perl 5 year 2000 compliant?
Message-Id: <bigiain-ya02408000R0502981603090001@news.ozemail.com.au>

In article <34da39a4.1384166@sd.znet.com>, Abraxas@hell.com (Tiberius) wrote:

> > RTFM...
> 
> Why do perl-ers so often insist on posting this worthless response,
> instead of just shutting up and not replying to what they believe is a
> stupid post?
> 
> Why?

probably because there's an important difference between:

"I'm not going to answer that post - for reasons which you'll never find
out (since i haven't answered)"

and

"the answer to that question is in the documentation - which you should
have read before posting here"

the second, while often posted in brusque or abrupt (or sometimes
frustrated and rude) replies, is actually *MUCH* more useful than the first
- if no-ones ever pointed you to the perl documentation, you could missing
out on one of perls finest resources.

cheers

iain

(who is eternally greatful to all those people who contributed to the
megabyte-and-a-half of documentation that comes with *EVERY* perl
installation, and all those cpan authors who document and comment their
code before giving it away. its not that hard to understand how quickly
they'd get tired of seeing questions that are answered in the FAQ and doco,
is it?)

Iain Chalmers
bigiain@mightymedia.com.au


------------------------------

Date: Wed, 04 Feb 1998 21:45:46 -0800
From: RandallBart <Barticus@worldnet.att.spam.net>
Subject: Re: Is Perl 5 year 2000 compliant?
Message-Id: <6bbk6m$9co@bgtnsc03.worldnet.att.net>

Abigail wrote:
> 
> David Lee Lambert (lamber45@EGR.msu.edu) wrote on 1618 September 1993 in

I just calculated this:  The 1618th day of Sepetember 1993 is today,
1998-02-04.

But Abigail, why does your program do that?  The original post had
today's date in a normal format.

-- 
I  |\   Randall Bart                      mailto:Barticus@usa.spam.net
L  |/   
o  |\        Barticus@worldnet.att.spam.net  Barticus@hotmail.spam.com
v  | \  1-818-985-3259                       Please reply without spam
e    |\ 
Y    |/ Panic in the Year Zero Zero:  http://members.aol.com/PanicYr00
o    |\ The 28th Term Revealed:
u    |/                 http://members.aol.com/PanicYr00/Sequence.html


------------------------------

Date: Thu, 5 Feb 1998 05:49:59 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Is this correct? File Locking
Message-Id: <ebohlmanEnw5JB.A9t@netcom.com>

Anthony Boyd <anthony@outshine.com> wrote:
: Jon Drukman <jsd@hudsucker.gamespot.com> wrote:
: > Bill Genzer <bill@fathead.net> wrote:
: > 
: > :  flock(FILE,8);
: > 
: > don't ever do this.  i don't know why it's in the faq, but randal
: > yelled at a friend of mine when said friend posted something including
: > this.  so don't do it.  close takes care of it for you.

: Can anyone explain the reasoning behind this?  I understand that close
: takes care of unlocking the file, but I didn't realize it was poor coding
: to do otherwise.  In fact, I felt like explicitly stating the unlock was
: "good coding".  I wan't to change that if there is a compelling reason.

Unless you explicitly arrange otherwise, most OSes buffer file output.  
Until you've explicitly close a file that you've written to, some of your 
output is sitting in a buffer in memory but hasn't yet been written to 
disk.  If you release a lock on a file before closing it, it's possible 
for another process to get in and start making its own modifications to 
the file before all your writes have made it to disk.  In that case, one 
process or another is going to have its output stomped on.



------------------------------

Date: Wed, 04 Feb 1998 23:14:26 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Is this correct? File Locking
Message-Id: <34D9589D.7A84C5A1@5sigma.com>

I'm not sure why myself.  LOCK_UN *does* flush the filehandle.
Maybe there are some systems where this doesn't work reliably?
Maybe there are other issues.  For example, I don't know whether 
all systems position to EOF before each write in append mode.

	-joseph

Anthony Boyd wrote:
> 
> Jon Drukman <jsd@hudsucker.gamespot.com> wrote:
> > Bill Genzer <bill@fathead.net> wrote:
> >
> > :  flock(FILE,8);
> >
> > don't ever do this.  i don't know why it's in the faq, but randal
> > yelled at a friend of mine when said friend posted something including
> > this.  so don't do it.  close takes care of it for you.
> 
> Can anyone explain the reasoning behind this?  I understand that close
> takes care of unlocking the file, but I didn't realize it was poor coding
> to do otherwise.  In fact, I felt like explicitly stating the unlock was
> "good coding".  I wan't to change that if there is a compelling reason.

-- 
Joseph N. Hall, prop., 5 Sigma Productions       mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training  . . . . . . . . . . . . . . .  http://www.perltraining.com


------------------------------

Date: Wed, 04 Feb 1998 22:40:09 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: killing a child process after a timeout
Message-Id: <34D95094.F0E2AF8E@5sigma.com>

Chip, someone might think you have an axe to grind.  :-)

	-joseph

Chip Salzenberg wrote:
> 
> According to "Rajan Troostwyk [8000885]" <troostwyk_rajan@jpmorgan.com>:
> >I found that the system calls would sometimes hang, so I added the
> >"manage_proc" and a "kill_child" functions included below. This seemed
> >to kill the child processes sometimes but other times I would get a
> >defunct child process and "manage_proc" function would hang at the
> >waitpid line ???.
> 
> You are using Perl signal handlers.
> 
> Don't.  They don't work reliably.
> 
> You must do what you want some other way.

-- 
Joseph N. Hall, prop., 5 Sigma Productions       mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training  . . . . . . . . . . . . . . .  http://www.perltraining.com


------------------------------

Date: Thu, 05 Feb 1998 05:14:11 GMT
From: sloop@mailcity.com (Dave O.)
Subject: Re: Mail checker....
Message-Id: <34d94993.159523482@news.xmission.com>

On Wed, 4 Feb 1998 17:26:08 -0500, Premgith  Vidyanandan
<vidyanan@pilot.msu.edu> wrote:

>
>
>I want to write a perl program that goes through my mail folder and based
>on the header of the mail or using the from address it puts the mail into
>separate folders..... I know that the mail file is kept in /var/mail... I
>just want to know the best way to read mail by mail as opposed to line by
>line and then to move the create a file and move the mail into that
>file... 
>   The programming part I can do but I would like to know how to access
>mail by mail as opposed to line by line....

Gosh, if anything sounds like the proper use of a .procmailrc filter
your task does.  Seriously, why mess with the raw mail when you could
have it filtered into various directories automatically at delivery
time?  I'd suggest looking at the man pages for procmail, procmailrc,
and forward.  You really can do cool things when you use the tools
intended for the job... and there's no reason that your procmailrc
file can't invoke a perl script if you really want to get fancy.

Dave


------------------------------

Date: Thu, 05 Feb 1998 00:33:09 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Multi-line blocks of text
Message-Id: <34D94F15.44C19821@coos.dartmouth.edu>

Laurens van Alphen wrote:
> 
> well.. i think i've finished to job somewhat.. this seems to work pretty
> well
> 
> it reads from stdin only and the first command line argument is the user
> that should be looked for. i'm just wondering if the input record seperator
> can be made case insensitive... never mind if it needs alot of coding...

Unfortunately not.  The input record separator is used as a literal string
rather than a regex.  Perhaps you could read the file in all at once and
split it, or read it in line by line and watch for the record separator
yourself.

Chipmunk


------------------------------

Date: Wed, 04 Feb 1998 22:38:20 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Optimizing dependency generation
Message-Id: <34D95028.2775E966@5sigma.com>

The way x11 makedepend and company get their speed is by cacheing 
the dependency trees.  If the second source file being processed
#includes some of the same files as the first, makedepend doesn't
bother doing the work over again.  Well, hell, you could just
read this in the man page:

ALGORITHM
     The approach used in this program enables it to run an order
     of magnitude faster than any other dependency generator that
     all files compiled by a single  makefile  will  be  compiled
     with roughly the same -I and -D options; and that most files
     in a single directory will include largely the same files.

     Given these assumptions, makedepend  expects  to  be  called
     once for each makefile, with all source files that are main-
     tained by the makefile appearing on the  command  line.   It
     parses  each source and include file exactly once, maintain-
     ing an internal symbol table for each.  Thus, the first file
     on the command line will take an amount of time proportional
     to the amount of time that a normal  C  preprocessor  takes.
     But  on  subsequent files, if it encounter's an include file
     that it has already parsed, it does not parse it again.

     For example, imagine you are compiling  two  files,  file1.c
     and file2.c, they each include the header file header.h, and
     the file header.h in turn  includes  the  files  def1.h  and
     def2.h. When you run the command

         makedepend file1.c file2.c

     makedepend will parse file1.c and consequently, header.h and
     then  def1.h  and def2.h. It then decides that the dependen-
     cies for this file are

         file1.o: header.h def1.h def2.h

     But when the program parses file2.c and discovers  that  it,
     too, includes header.h, it does not parse the file, but sim-
     ply adds header.h, def1.h and def2.h to the list  of  depen-
     dencies for file2.o.

Hashes and references make this trivially simple once you have parsed
the files for includes.  How much of the macro preprocessor you
want to emulate in your Perl script is up to you.  You would probably
at least want to keep track of simple #defines and #ifdefs, since
header files are often conditionally included.  Writing a complete
preprocessor is a much more difficult task.

The simplest thing, of course, is to let gcc do the work for you.

-- 
Joseph N. Hall, prop., 5 Sigma Productions       mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training  . . . . . . . . . . . . . . .  http://www.perltraining.com


------------------------------

Date: Wed, 04 Feb 1998 23:34:11 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Optimizing regular expression
Message-Id: <34D95D3E.C3EE1D26@5sigma.com>

For one thing, if you only want to match certain lines, you should
probably be pre-testing them ...

  if (m{ /rotations/graphics| /cgi-bin/clickoff}) {...
	# now take time to parse the line ...

It might also be faster to pre-select lines by piping the
output of grep into your Perl program, or taking lines from
open GREP, "grep my-pattern-here my-file-here|".

For your second question, learn to use the Benchmark module.

There's a logfile parser module too.

	-joseph

Jon Drukman wrote:
> 
>   my ($ip, $type, $adcode, $status) = m{
>     ([0-9.]+)   # ip address
>     .*          # skip stuff
>     (/rotations/graphics/|/cgi-bin/clickoff.pl\?) #anything up to /rotation or /cgi
>     (.*_a)      # the Ad ID code is here
>     .*?\s       # skip some more
>     (\d+)       # until we see the result code
>   }x;

-- 
Joseph N. Hall, prop., 5 Sigma Productions       mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training  . . . . . . . . . . . . . . .  http://www.perltraining.com


------------------------------

Date: Thu, 05 Feb 1998 01:13:49 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: stewart samuel bushman <sbushman@students.uiuc.edu>
Subject: Re: Perl Stock Quote Retriever
Message-Id: <34D9589D.2F49B4DD@coos.dartmouth.edu>

[posted and mailed]

stewart samuel bushman wrote:
> 
> For your perusal...it's kludgy, but it works.  If anyone wants to improve
> on it, I'll gladly take a copy.
> 
> # Call up Yahoo, and get the page for the symbol ORCL (for example)
> use LWP::Simple;
> $doc = get 'http://quote.yahoo.com/q?s=orcl';

Instead of hard-coding the symbol, get it from the command line and
stick it in a variable.

> # Search through for string before quote info and delete all before
> $_ = $doc;
> /q?s=ORCL&d=t">/;
> $firstcrop = "$'";

If you want to match a literal ?, you need to backslash it:
/q\?s=ORCL&d=t">/;

You should do case-insensitive matching using /i.

You don't need to use double quotes for a single variable.

Don't use $' and $`.  It slows down every regex in your script.
You could replace this with:
/q\?s=ORCL&d=t"(.*)/si;
$firstcrop = $1;

$firstcrop is a confusing name for this variable.  It's not what
you're cropping, it's what you're saving.

> # Search through for string after quote info and delete all after
> $_ = $firstcrop;
> /<a href="/;
> $secondcrop = "$`";

You don't have to assign to $_ just to do a pattern match.
$firstcrop =~ /<a href="/i;

In fact, you don't even have to assign to $firstcrop;
just use $1.

A way to do it without $`
($data = $1) =~ s/<a href=".*//si;

> # Remove all HTML coding (courtesy of the FAQ)
> $_ = $secondcrop;
> $secondcrop =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;

(Once again, you don't need to assign to $_.)

Use HTML::Parse.

> # Dump to output
> print $secondcrop;
> exit;

Instead of stripping all the HTML coding, you could do a little formatting
so your output is nicer.  (Paying attention to <P>, <BR>, and such.)

Chipmunk


------------------------------

Date: Thu, 05 Feb 1998 06:07:18 GMT
From: gwynp@artware.qc.ca (Philip)
Subject: PGP5, open3 and cgiwrap
Message-Id: <34d951e7.33277661@nntphost.login.net>

I'm currently re-writing the PGP::Pipe modules so they work with PGP
5.0 (latest Unix version).  I decided to abandon PGP 2.6.3, so I
renamed the modules to PGP5::*

I've got pretty everything working at the command line but (whine of
the decade) it fails during CGI.

What I've been able to diagnose:
PGP5::Pipe uses IPC::Open3::open3 to call the actual PGP binary.  This
means we get the STDIN, STDOUT and STDERR from the PGP process and we
don't ever have to write clear-text to disk (unless caller wants to).
When I call do this form the command line, PGP's STDOUT contains the
interesting info, PGP's STDERR contains error messages, warning
messages and other information.  When I call open3 via CGI, PGP's
STDOUT is empty and all output information is received via PGP's
STDERR.  I hmmmed and hawed a bit (more like curse swear) then worked
around the problem by regexing the pertinant info from PGP's STDERR.  

However, I would like to know *why* this is happening.  One idea I
came up with is that I'm using cgiwrap, a niffty CGI wraper that,
amoungst other things, causes the CGI's STDERR to be redirected to the
CGI's STDOUT.  My guess that this would then mean that when
IPC::Open3::_open3 does it's xopen, xclose etc. on \*STDERR, it is
also affecting \*STDOUT.  I'm no expert at spawning, piping and such
stuff.

Here is a rough idea of the code:

sub Exec
{
    my ($self, $type, $args, $fin, $fout, $ferr, $nobatchmode) = @_;
    if ($nobatchmode)
    {   $baseopts = '+force +verbose=1' }
    else
    {   $baseopts = '+force +batchmode +verbose=1' };

    # some fooling around with $type and $args
    # $exec ends up as /usr/local/bin/pgp[esdvk] depending on $type

    my $result = open3($fin, $fout, $ferr, "$exec $baseopts $args") or
        croak "PGP5 $exec command error: $!";

    return $result;
}

This is called as

    $options="-fat -f0xABC1234EF";
    $self->Exec('encrypt', $options, *FIN, *FOUT *FERR);
    print FIN $clear_text;
	
At the command prompt, <FOUT> would then containt the encrypted data,
<FERR> some warning messages.  When called via CGI, <FOUT> is empty
and <FERR> has warning messages and encrypted data.


------------------------------

Date: 5 Feb 1998 06:33:56 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Quickie: regexp for valid e-mail addresses
Message-Id: <6bbmgk$q8m$1@client3.news.psi.net>

Woody Jin (wjin@cs.uh.edu) wrote on 1619 September 1993 in
<URL: news:6bbbq6$c8u$2@Masala.CC.UH.EDU>:
++ 
++ In article <6ba6eu$b4v$3@client3.news.psi.net>, abigail@fnx.com wrote:
++ 
++ >Note that mailer programs don't validate. 
++ 
++ Mailer programs don't validate, but we can use mail daemons.

Which I had in mind. They don't validate. They parse. And then they
try to get rid of it as quickly as possible. "I don't handle this,
but you do. Here, have fun". 

++ For example, I remember that I was able to use - I don't remember the
++ option correctly - "/usr/lib/sendmail -bv user@host.name" 
++ to see whether it is deliverable (it may not work correctly depending

Not whether it's deliverable. They check if they have some rule to
pass the bucket. And then they try for five days (or longer) to pass
the bucket. Many machines are also configured to deliver all mail
to a single machine, which then takes care of it. 

++ on the sendmail configuration. but then you can set up the config
++ file and use sendmail option to use the alternate config file).
++ 
++ Also, you can directly telnet to the mail port and use VRFY command.

Yeah? I'll give you two addresses. You figure out where to telnet
to to verify. One is valid, the other isn't. Here they are:
      abigail@venus.ic.iaf.nl
      abigail@mars.ic.iaf.nl

You won't even be able to verify the *domain*, let alone the user.

++ For example,  "telnet cs.uh.edu 25" and then,
++ "VRFY wjin" will give you, my name and e-mail address
++ "VRFY wwwwjin" will give you "User unknown".
++ So, there is obviously a way to verify users.

Yes, and you don't exist!

[abigail@betelgeuse] abigail) nslookup -type=mx cs.uh.edu | grep exchancher
cs.uh.edu       preference = 20, mail exchanger = post-office.uh.edu
[abigail@betelgeuse] abigail) telnet post-office.uh.edu smtp
Trying 129.7.1.20...
Connected to post-office.uh.edu.
Escape character is '^]'.
220 Post-Office.UH.EDU -- Server ESMTP (PMDF V5.1-10 #18580)
VRFY wjin
550 5.1.1 String does not match anything.
VRFY wwwwjin
550 5.1.1 String does not match anything.
VRFY wjin@cs.uh.edu
252 2.5.0 Possible remote address not checked.
VRFY wwwwjin@cs.uh.edu
252 2.5.0 Possible remote address not checked.
QUIT
221 2.3.0 Bye received. Goodbye.
Connection closed by foreign host.
[abigail@betelgeuse] abigail)                                QED



Now, did I mention UUCP? Yes, I did, though it's hard to spot.



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


------------------------------

Date: Wed, 04 Feb 1998 22:26:18 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: split /\s*,\s*/
Message-Id: <34D94D56.6C4BA5E4@5sigma.com>

So, how do you expect things to work?  If you use the empty
string as a number, it's a zero.  You might try using the -w
option.

	-joseph

Steven Smith wrote:
> 
> I'm trying to use split to separate fields on an input string
> that sometimes has ,,, in it. when this happens and my split
> pattern is /\s*,\s*/, I get a 0 element array back.  If I
> split on /,/, things work as I expect.  What am I missing?

-- 
Joseph N. Hall, prop., 5 Sigma Productions       mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training  . . . . . . . . . . . . . . .  http://www.perltraining.com


------------------------------

Date: Wed, 04 Feb 1998 23:29:16 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Tie-Dee-Perl (Cleanliness is next to Goodliness, or Perl-White Code)
Message-Id: <34D94E2C.7CD08196@gpu.srv.ualberta.ca>

I R A Aggie wrote:

[snip]
> 
> +    open NUMBERS, "irrationals.txt" or die "Damn irrationals.txt is big: $!";
> 
> Danger! Danger, Will Robinson! If memory serves (and the perlop manpage
> indicates this is true), the way this is going to be evaluated is like:
> 
> (open NUMBERS), ("irrationals.txt" or die...)
> 
> The evaluation will attempt to do the "or" first, then the open. Not
> necessarily what is wanted!!

my perlop manpage indicates that 'or' is at the bottom
of the precendence list...so:
open SOMETHING, 'somefile' or die "Kant $!";
works fine... 
you want parentheses if using the '||' operator though.
open(SOMETHING,'somefile')||die "Kant $!";

regards
andrew


------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 1814
**************************************

home help back first fref pref prev next nref lref last post