[6332] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 954 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 15 01:27:20 1997

Date: Fri, 14 Feb 97 22:00:20 -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           Fri, 14 Feb 1997     Volume: 7 Number: 954

Today's topics:
     Re: "scalar each"  - what does it mean? <brett@speedy.speakeasy.org>
     $! Error Handling <geoffrey.halliwell@Sun.COM>
     Re: $! Error Handling ()
     Re: 4-arg select() and buffered I/O question (Andrew M. Langmead)
     Re: [Q] how do I grok this: ${*$obj}{'whatever'} = $foo <roderick@gate.net>
     Bug in Perl f77 namelist module (Guy Berliner)
     Re: Case insensitive comparison (Brian L. Matthews)
     Re: fflush() in Perl? <groves@goodnet.com>
     Re: fflush() in Perl? (Tad McClellan)
     File write permissions in Perl <jjacobs@incnet.com>
     Re: Forcing Completion of System() Call <jlguru@cris.com>
     Re: HELP loop prob (Andrew M. Langmead)
     Re: Help:# Can't find string terminator "ending_print_t (Tad McClellan)
     How to REMOTE_HOST Lookup for Access ? <rwatkins@crosslink.net>
     Re: HOW TO SPLIT A SIMPLE STRING (Bob Mariotti)
     Re: My first PERL cgi, please critique <joiner@houston.omnes.net>
     Re: PROGRAM: how to check for nice/valid email address ()
     QUES: what is "undump"? (John Nolan)
     Re: Questions about formline <rsk@cris.com>
     Re: Randal trashed yet again--*sigh* (Kevin Buhr)
     Re: Randal trashed yet again--*sigh* <brett@speedy.speakeasy.org>
     Re: Randal trashed yet again--*sigh* (Thomas Andrews)
     Re: RegEx, Email & Friedl's "Mastering..." Book (Tad McClellan)
     Re: regexp's in XEmacs vs. Perl <hniksic@srce.hr>
     Regular Expressions and Assigning to Variable (Michael Nelson)
     The Power And Peril Of Writing Perl CGI Code - Lan Time jim@netcom.com
     Re: using "$var" considered harmful?! (was Re: Q: openi (Andrew M. Langmead)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: 14 Feb 1997 16:01:16 -0800
From: Brett McCormick <brett@speedy.speakeasy.org>
Subject: Re: "scalar each"  - what does it mean?
Message-Id: <7venejdjjn.fsf@speedy.speakeasy.org>


Hmmm, interesting..  I was unaware that there was a difference between
arrays and lists..  I assume that a list is one or more perl types,
where as an array is a perl type (which happens to contain 0 or more
other perl types?_

--brett

Tom Christiansen <tchrist@mox.perl.com> writes:

> 
> There is a logic error there:
> 
>     1 each returns a list of two elements
>     2 when you evaluate a list as a scalar, you get its count
> 	(actually, you usually get the last element of the
> 	 list; it's an array that gives you its count)
>     3 therefore each as a scalar is its count


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

Date: Fri, 14 Feb 1997 14:56:45 -0800
From: Geoff Halliwell <geoffrey.halliwell@Sun.COM>
Subject: $! Error Handling
Message-Id: <3304EDAD.2C03@Sun.COM>

Greetings!

How do you capture $! in a numeric context
when opening a file?

	open(LOG, /unknown_dir);

Or is there a better why to manage error
handling?

Thanks in advance,

Geoff Halliwell


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

Date: 14 Feb 1997 19:18:11 -0800
From: sveerara@sveerara-ultra.cisco.com ()
Subject: Re: $! Error Handling
Message-Id: <ls3lo8qwydo.fsf@sveerara-ultra.cisco.com>


I think you might need the warn operator, unlike die it does not exit.
It is described on Pg 201 Camel Book.

		----ranga



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

Date: Fri, 14 Feb 1997 22:41:21 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: 4-arg select() and buffered I/O question
Message-Id: <E5M70y.L26@world.std.com>

bierman@apple.com (Peter Bierman) writes:

>> There are two cases where select and the buffered input operators fall
>> over each other.
>> 
>> 1. An incomplete line is sent to the process. select() will then
>> return because there is input. The diamond operator will then block on
>> a second sysread() because it wants to combine as many sysread()s as
>> necessary to return a full line.

>Is the only bad side effect of this that you will block until that socket
>recieves a full line?

Since people often use select() to monitor multiple sockets, blocking
on one that isn't ready can be a pretty bad side effect.

>And an only slightly related question: What's the best way to recover from
>a network disconnect? Like a timout, or if the client at the other end
>just dies. If I use a SIGALRM, what's the best way to deal with multiple
>connections if I'm using select? Is there a better way than SIGALRM?

If you using select(), you might want to dispense with alarms entirely
and just use the timeout mechanism built into the select() call. Maybe
keep a list of sockets with their timeout values. Make the fourth
argument of select() the earliest timeout. If select() returns without
reporting data for a file descriptor, and the current time is later
than the sockets timeout value, consider it dead.

-- 
Andrew Langmead


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

Date: 14 Feb 1997 22:51:11 -0500
From: Roderick Schertler <roderick@gate.net>
To: nelson <nmljn@wombat.staff.ichange.com>
Subject: Re: [Q] how do I grok this: ${*$obj}{'whatever'} = $foo
Message-Id: <pzafp6zq9n.fsf@eeyore.ibcinc.com>

On 06 Feb 1997 11:17:14 -0500, nelson <nmljn@wombat.staff.ichange.com> said:
> 
> Now, in Net::POP3, to take a totally arbitrary example, we have:
> 
>     my $obj = $type->SUPER::new(PeerAddr => $host, [...]
[...]
>     ${*$obj}{'net_pop3_host'} = $host;
[...]
> So $obj will be an object (a ref that knows what package it belongs
> to).  But what is the value of ${*$obj}?

I think this is where you went wrong, that's the wrong question.
Talking about ${*$obj} from the above code doesn't make sense, because
it's part of a hash element access.  It's like looking at

    $hash{'key'} = 'value';

and asking what $hash represents -- $hash doesn't represent anything
connected to the code.

That ->new call is inheriting from IO::Socket, which in turn is
inheriting from IO::Handle.  The important part of IO::Handle's version
is

	my $fh = gensym;
	bless $fh, $class;
    
gensym is Symbol::gensym, it returns a reference to an anonymous glob.
So, working inside out, *$obj is just dereferencing the glob ref (just
like $$scalarref or @$arrayref).  ${*$obj}{'net_pop3_host'} is just like
${*glob}{'net_pop3_host'} which is like $glob{'net_pop3_host'}.  So,

    ${*$obj}{'net_pop3_host'} = $host;

is assigning to the key 'net_pop3_host' in the hash component of the
glob referenced by $obj.

Graham Barr is using a glob ref as the object underlying the IO::*
modules so that he can have both the filehandle (in the filehandle slot
of the glob) plus auxiliary information (in the hash slot).  Most code
won't need this functionality, it's only necessary if the user needs to
be able to treat the object as a filehandle (using print $fh "foo", eg).
(It's just like using \*STDOUT to pass the STDOUT handle to a user
subroutine under 'use strict'.)  If it weren't for this requirement I'm
sure Mr. Barr would have simply used a hash ref as the object.

-- 
Roderick Schertler
roderick@gate.net


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

Date: Sat, 15 Feb 1997 00:26:34 GMT
From: berliner@netcom.com (Guy Berliner)
Subject: Bug in Perl f77 namelist module
Message-Id: <berlinerE5MBwA.Es4@netcom.com>

[Pardon me if some of you see this article multiple
times. I realized after my first post that I should
have also cross-posted to comp.lang.fortran. I have
already cancelled the previous posts.]

I created an extension module that may prove useful
to anyone using Fortran and the namelist extension
provided by, for example, the Sun f77 compiler. I
defined a Perl class called "Nmlfile", which lets you
read in namelist files using the Perl syntax:
my $nmlfile = new Nmlfile($filehandle);
$nmlfile->readnml;
$variable = $nmlfile->variable;
$nmlfile->printnml("nmlname" => "mynml");
etc.

I would like to distribute this via CPAN.
The problem is that when I read in character
strings, random junk sometimes gets appended
to them in my extension subroutine. Otherwise,
the module works great. Does anyone have any
interest in helping me to debug this problem?
Anyone out there have a use for Perl as glue
for legacy Fortran software?

Guy Berliner

-- 
Finger berliner@netcom18.netcom.com for pgp key.


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

Date: 14 Feb 1997 16:25:56 -0800
From: blm@halcyon.com (Brian L. Matthews)
Subject: Re: Case insensitive comparison
Message-Id: <5e2vqk$igj$1@halcyon.com>

In article <5e2cvf$8a6$1@halcyon.com>,
Brian L. Matthews <blm@halcyon.com> wrote:
|Of course this is a fair bit slower than just lower-casing everything:
|Benchmark: timing 100000 iterations of RE, RE const, lc, lc const...
|        RE: 23 secs (20.08 usr  0.57 sys = 20.65 cpu)
|  RE const: 20 secs (10.62 usr  0.88 sys = 11.50 cpu)
|        lc: 12 secs ( 6.43 usr  0.47 sys =  6.90 cpu)
|  lc const: 11 secs ( 3.77 usr  0.38 sys =  4.15 cpu)

Oops, naughty me. I forgot the /o on the end of the one match where
I interpolate a string. It's still slower than lc'ing both strings,
but not so much slower:

use Benchmark;

$str1 = 'A(b)c';
$str2 = 'a(B)c';

timethese (100000,
    {
	'RE' => '$str1 =~ m/^\Q$str2\E$/io',
	'RE const' => '$str1 =~ m/^a\(b\)c$/i',
	'lc' => 'lc $str1 eq lc $str2',
	'lc const' => '\'a(b)c\' eq lc $str2'
    });

Benchmark: timing 100000 iterations of RE, RE const, lc, lc const...
        RE: 18 secs (11.20 usr  1.00 sys = 12.20 cpu)
  RE const: 11 secs (10.75 usr  0.22 sys = 10.97 cpu)
        lc:  9 secs ( 7.40 usr  0.32 sys =  7.72 cpu)
  lc const:  5 secs ( 4.48 usr  0.07 sys =  4.55 cpu)

Brian
-- 
Brian L. Matthews				Illustration Works, Inc.
	For top quality, stock commercial illustration, visit:
		  http://www.halcyon.com/artstock


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

Date: Fri, 14 Feb 1997 18:32:40 -0700
From: Jeff Groves <groves@goodnet.com>
To: Henry Wu <henryw@seasick.sps.mot.com>
Subject: Re: fflush() in Perl?
Message-Id: <33051238.71C0@goodnet.com>

Henry Wu wrote:
> 
> I have a simple question.  Is there a function in Perl corresponding to
> the C fflush() function?  I used mutiple "print" statements in a Perl
> script, but the results didn't show on STDOUT instantly until the end of
> the program.  So I want to flush the STDOUT after each "print"
> statement.  Can anyone out there give me a clue?  Thanks.
> 
> -Henry

Do this before your first "print"...

$old_filehandle = select(STDOUT);
select(STDOUT);
$| = 1;      # this disables buffering
select($old_filehandle);


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

Date: Fri, 14 Feb 1997 22:56:43 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: fflush() in Perl?
Message-Id: <bmf3e5.id4.ln@localhost>

Henry Wu (henryw@seasick.sps.mot.com) wrote:
: I have a simple question.  Is there a function in Perl corresponding to
: the C fflush() function?  I used mutiple "print" statements in a Perl
: script, but the results didn't show on STDOUT instantly until the end of
: the program.  So I want to flush the STDOUT after each "print"
: statement.  Can anyone out there give me a clue?  Thanks.
                                   ^^^^^^^^^^^^^^

man perlfunc and perlvar (search for flush)

You didn't really need to post to get a clue, just check the free
documentation that is included with the perl distribution...


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Fri, 14 Feb 1997 21:49:17 -0600
From: Jay Jacobs <jjacobs@incnet.com>
Subject: File write permissions in Perl
Message-Id: <3305323D.3E05@incnet.com>

I am trying to create an HTML form to update news stories on a company
web site.  I have most everything written, but the only way I can get it
to write to a file (in perl from a script) is by opening up the
directory permissions to everyone.  I was wondering if there was a
better way than to open it up like that?  It will be going onto a rather
public server and I would rather not "hope for the best".  I'm running
on a unix box with perl 5.

Jay Jacobs
(please respond via e-mail also)


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

Date: Fri, 14 Feb 1997 16:49:48 -0700
From: "Jerry L. Gubka" <jlguru@cris.com>
Subject: Re: Forcing Completion of System() Call
Message-Id: <3304FA1C.2AD4@cris.com>

Jerry L. Gubka wrote:
> 
> I am running Perl 5.001 under WinNT 4.0. My script repetitively executes
> several system() calls to execute external programs that generate
> Autocad DXF files, then executes Acad to import the DXF files, plot the
> drawings to a file, save the drawing, end Acad, and run PKZIP to
> cumulate the resulting drawings/deferred plot files.
> 
> My problem is that Perl does not execute the system() calls sequentially
> (as in Win95). Rather, it blithely continues generating DXF files even
> as Acad is striving to catch up and I end up with multiple instances of
> Acad running simultaneously. That would be OK, but in the process some
> temporary files get stomped over resulting in a mess.
> 
> My question is, how do I force Perl to wait for a system() call to
> complete before continuing? I tried using wait() but received an
> "unimplemented feature" error message.
> 
> I recall this question being asked here before, but I cannot find
> references to those postings in either Dejanew or Alta Vista; and, I can
> find no help in either the manpages or the online FAQ's.
> 
> Thanks in advance ...
> 
> Live long, and prosper
> Jerry L. Gubka

Never mind ... I found I was using a 4NT.EXE alias that utilizes the
"start" command to execute ACAD. This resulted in the multiple instances
of ACAD running simultaneously. When I substituted a direct path to
ACAD.EXE, all was well.

Live long, and prosper
Jerry L. Gubka


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

Date: Fri, 14 Feb 1997 22:19:12 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: HELP loop prob
Message-Id: <E5M600.8yK@world.std.com>

Lewis Taylor <lewis@thereel.com> writes:

>for ($i=1; $i <= 14; $i++)

>{
>$field=$FORM{'qu$i'};
>print OUTPUT ":$field";
>}

>but this loop (and variations) do not seem to work. What a I doing
>wrong?


Take a look at what the documentation (the perldata and perlop man
pages in particular) says about the differences between single and
doubled quotes. Double quotes interpolate variables, single quotes do
not.

    $field=$FORM{"qu$i"};

or use the string concatination operator:

    $field=$FORM{ 'qu' . $i };




-- 
Andrew Langmead


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

Date: Fri, 14 Feb 1997 16:02:07 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Help:# Can't find string terminator "ending_print_tag" anywhere before EOF.
Message-Id: <vcn2e5.i03.ln@localhost>

Keith Warner Colvin (colvin@aloha.net) wrote:
: Aloha from Hawaii,

: I am trying to write my first .cgi:

: #! /usr/local/bin/perl
: print "Content-type: text/html/n/n";

: print <<"ending_print_tag";
: <html>
: <head>
: <title>The First CGI</title>
: <background="000000"  text="#FF0000" >
: </head>
: <body>
: <h1> My First CGI</h1>
: <i> HELLO INTERNET</i>
: <hr noshade>
: Items of importance go here.....
: <body>
: </html>
: ending_print_tag>>
                  ^^

: and I get this response when I run the script:

: # Can't find string terminator "ending_print_tag" anywhere before EOF. 

: What do I do next?
  ^^^^^^^^^^^^^^^^^

You remove the >>    ;-)


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Fri, 14 Feb 1997 21:37:52 -0500
From: Richard Watkins <rwatkins@crosslink.net>
Subject: How to REMOTE_HOST Lookup for Access ?
Message-Id: <33052180.6D5A@crosslink.net>

I am new a Perl and can't find any examples of a short script for
implementing
a Remote Host (REMOTE_HOST) or Remote IP address (REMOTE_ADDR) look-up
routine
that would only allow access to a web page if a HOST or IP ADDRESS is
listed
in a certain file.

I know its not the most secure method of resticting unwanted surfers
from entering
your page, but I have a wep page of two that some people in my company
are putting
pressure on me to restrict access to only certain individuals.  The
pages are not
that critically sensitive, but the idea is similar to putting a padlock
on a door -
It won't stop a good thief but it will keep most people away.

I have written two small Perl scripts, a web counter and a mailer, so I 
have a little experience and currently hungry to learn more.

If anyone has an example or other URL to reference, it would be a big
help.
 
Thank you,

Rick Watkins
rwatkins@crosslink.net


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

Date: Sat, 15 Feb 1997 02:20:06 GMT
From: rmariott@tiac.net (Bob Mariotti)
Subject: Re: HOW TO SPLIT A SIMPLE STRING
Message-Id: <5e366j$b32@news-central.tiac.net>

You might try this:

($fld1,$fld2,$fld3,$fld4)=unpack(a2a2a2a2,$infld);

Works for me!
-------------------------------------------------
 Bob Mariotti          Financial DataCorp (FDC)
 bobm@cunix.com        Credit Union Specialists
 (860) 657-8983 voice  703 Hebron Avenue
 (860) 657-8987 fax    Glastonbury, CT 06033 USA
-------------------------------------------------



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

Date: Fri, 14 Feb 1997 17:18:53 -0600
From: Paul Joiner <joiner@houston.omnes.net>
Subject: Re: My first PERL cgi, please critique
Message-Id: <3304F2DD.28DD@houston.omnes.net>

A. Deckers wrote:
>..._Always_ enable warnings:
> 
> #!/usr/local/bin/perl -w

I have to partly disagree. *Certainly do it during the development
phase.* However, there are several modules that will generate warnings
ad infinitum. They work. They're beautiful. But they will totaly screw
up your headers if you're using -w.

Use -w while developing your script to check for the easy stuff.

You might want to add -T to force taint-checking of data. This won't
screw up the headers and will let you know if you're doing anything that
might expose your system to unscrupulous users.

-- 
paul joiner, graphic designer - joiner@houston.omnes.net
ftp://paulj.houston.omnes.net/ - http://paulj.houston.omnes.net
pjoiner@nol.net - http://www.nol.net/~pjoiner


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

Date: 14 Feb 1997 16:29:38 -0800
From: sveerara@sveerara-ultra.cisco.com ()
Subject: Re: PROGRAM: how to check for nice/valid email address
Message-Id: <ls3pvy2x66l.fsf@sveerara-ultra.cisco.com>


I'm not sure if there are any problems with this but,

	sendmail -bv

seems to work okay for me.  man sendmail for more details...

	----ranga


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

Date: 10 Feb 1997 02:09:43 GMT
From: sg94bwh5@dunx1.ocs.drexel.edu (John Nolan)
Subject: QUES: what is "undump"?
Message-Id: <5dm017$jcl@noc2.drexel.edu>

In Programming Perl (2nd ed, page 336), they mention in passing
that you can take the coredump of a compiled perl script, 
"undump" it using the undump program, and create an 
executable.  Does anyone know what undump is?  

Please forgive me if this is a stupid question.
I'd appreciate any info or pointers. 
--
###  John Nolan  
###  jpn@acm.org                               ~       __0    
###  sg94bwh5@dunx1.ocs.drexel.edu            ~      _`\<,_   
###  Drexel University, Philadelphia         ~      (_)/ (_) 

To learn and keep on learning prodigiously from birth to death 
is what sets us off from the other animals. It is our destiny on 
this planet. 

         -- George Leonard



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

Date: Fri, 14 Feb 1997 14:32:22 -0500
From: "Robert S. Kissel" <rsk@cris.com>
Subject: Re: Questions about formline
Message-Id: <3304BDC6.167E@cris.com>

I asked about the following code fragment:
> 
>    formline 'Text: ^' . ('<' x $L) . "\r\n", $Text;
>    formline '~~    ^' . ('<' x $L) . "\r\n", $Text;
> 
and the change to:
> 
>    $format[0] = 'Text: ^'.('<'x$L)."\r\n";
>    $format[1] = '~~ ^<<<'.('<'x$L)."\r\n";
>    formline $format[0], $Headline;
>    formline $format[1], $Headline;
> 
I've now found that I get different behaviors if the assignments
to @format take place repeatedly (unnecessarily), as opposed to
when the assignment is done ONCE.  In other words, when I included
a fragment like the one above in a SUBROUTINE, it would fail on the
second and subsequent calls, including (in my case) a double tilde
on subsequent lines of the formatted text.  This is starting to look
like an interpreter bug to me.

I will try to construct a minimal reproduction case and post it, unless
someone would care to comment that it is a known bug, or that I am
overlooking something.

Thank you again for your kind attention.


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

Date: 14 Feb 1997 18:13:12 -0600
From: buhr@stat.wisc.edu (Kevin Buhr)
Subject: Re: Randal trashed yet again--*sigh*
Message-Id: <vba3euzexk7.fsf@mozart.stat.wisc.edu>

nvp@shore.net (Nathan V. Patwardhan) writes:
> 
> Where was Randal mentioned in this article?

For some bizarre reason, some versions of Netscape will not "Find" any
words in the text of this Fortune article.  I'm not sure why.

Randal *is* mentioned in the article.  Hunt for mention of his name
manually, or use "lynx", and you'll find it.

Kevin <buhr@stat.wisc.edu>


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

Date: 14 Feb 1997 17:10:06 -0800
From: Brett McCormick <brett@speedy.speakeasy.org>
Subject: Re: Randal trashed yet again--*sigh*
Message-Id: <7v914qeuxd.fsf@speedy.speakeasy.org>


I beleive it has to do with the text being inside of tables.
ah, the BRAIN_DAMAGE

--brett

buhr@stat.wisc.edu (Kevin Buhr) writes:

> 
> nvp@shore.net (Nathan V. Patwardhan) writes:
> > 
> > Where was Randal mentioned in this article?
> 
> For some bizarre reason, some versions of Netscape will not "Find" any
> words in the text of this Fortune article.  I'm not sure why.
> 
> Randal *is* mentioned in the article.  Hunt for mention of his name
> manually, or use "lynx", and you'll find it.
> 
> Kevin <buhr@stat.wisc.edu>


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

Date: 14 Feb 1997 17:12:31 -0800
From: thomaso@best.com (Thomas Andrews)
Subject: Re: Randal trashed yet again--*sigh*
Message-Id: <5e32hv$814@shellx.best.com>

>In article <5dvo3r$akd@fridge-nf0.shore.net>, nvp@shore.net (Nathan V.
>Patwardhan) wrote:
>
>+ Clinton Pierce (cpierce1@cp501.fsic.ford.com) wrote:
>+ 
>+ :  http://pathfinder.com/@@yMtBXQUApoF4m2Oe/fortune/1997/970203/eml.html
>+ 
>+ Where was Randal mentioned in this article?
>
>Begin quote:
>
>+ Computer attacks can originate anywhere. Even in the age of the 
>+ globe-girdling Internet, the perp frequently is no farther away than the 
>+ office next door. At Intel, a technical contractor named Randal Schwartz 
>+ used his access to company premises to steal a password file from a 
>+ network server. The file was encrypted, or scrambled, for safety, but 
>+ Schwartz simply ran a program designed to break the codes. Intel had him 
>+ arrested before he did any damage. 
>

This reeks of hysteria.  Is the computer security field so desperate for
anecdotes that they need to use this one as an example?

I love the last sentence:
"Intel had him arrested..." is a lovely turn of phrase, no doubt without
and deliberate intonations of the ownership of the police.

"...before he did any damage."  Lovely.  The implication, of course,
is that Randal had intent to do damage.  Did Intel present such evidence
in court?
-- 
==
Thomas Andrews         thomaso@best.com         http://www.best.com/~thomaso/
  "In the end, Bork's book does raise questions, but the principal
   one is:  What planet does he live on?" - David Cole, Wash. Monthly


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

Date: Fri, 14 Feb 1997 23:02:39 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: RegEx, Email & Friedl's "Mastering..." Book
Message-Id: <f1g3e5.id4.ln@localhost>

24601 (cggatt@worldnet.att.net) wrote:
: Any help would be appreciated - 

: In Friedl's book there is an example of parsing email headers that are
: all single line entries. I am trying to match to headers that have
: multiple line selections like the following -

: Received: Blah BLah
: 	    Blah BLah
: Date: BLah Blah

:  I am reading the email header as one continuos string instead of
: saving to file and reading from STDIN. Right now, I match on the colon
: and the word metacharacters. Problem - I use (.*) to match everything
: after the colon and this breaks on the \n. How would I tell the
: expression to match the multiple line, as above, but go back to
: matching normally on the 'Date:' line. Again, any help is appreciated.


m/Received: (.*)^\S/sm;
                    ^^
                    ^^

for 'matching normally' you'll need a different pattern match
without the 's'


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 15 Feb 1997 02:01:48 +0100
From: Hrvoje Niksic <hniksic@srce.hr>
To: tchrist@mox.perl.com (Tom Christiansen)
Subject: Re: regexp's in XEmacs vs. Perl
Message-Id: <kig3euyq3ur.fsf@jagor.srce.hr>

Tom Christiansen <tchrist@mox.perl.com> writes:

> I never realized that emacs was happy to use syntax classes within
> character classes, as perl can do with things like [\-.\w\s].

Emacs can't do it.  You are right -- I wasn't reading carefully
enough, assuming that the poster meant to say that Emacs cannot handle
things like `\s' in regexps.

However, do notice that the substitute of `\s' with `[ \t\n]' is
always wrong, as Emacs uses customizable syntax tables (and I'd guess
Perl at least checks the current locale) to determine whether
something is whitespace or not.

> 	"EMACS belongs in <sys/errno.h>: Editor Too Big!" -me

Who said it was an editor??

-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
WWW:          World-Wide-Waste.  Waste management corporation, which
              handles the billions of tons of garbage generated by just
              about everybody these days.


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

Date: 15 Feb 1997 04:41:01 GMT
From: nelson@seahunt.imat.com (Michael Nelson)
Subject: Regular Expressions and Assigning to Variable
Message-Id: <slrn5gafis.34k.nelson@seahunt.imat.com>

Hi...

I'm writing a small program to parse some data out of a web page
and then print it out in another form.  My problem is this... I 
need to find lines of the form:

    <th align=middle valign=top>1548</th>
    
 ...and parse the number out of it, in this case, "1548".

I'm finding the lines ok, but having problems parsing the number
out and dumping it into a variable.  I've tried several variations
on the following, but I guess I don't understand how to get it to
find a ">", followed by one or more digit chars, followed by a "<".

Some things I've tried:

	$variable =~ />\d+</;
	$variable =~ /\>\d+\</;
	$variable =~ (/\>\d+\</);
	$variable =~ (/\>(\d+)\</);
	$variable =~ ((/\>)(\d+)(\</));
	
 ...I have earlier initialized $variable to "0", but I never seem
to get a match, even when a pattern like ">1548<" exists in the
line. $variable always stays set to "0".

Sure makes me feel like a dummy... 
	
Thanks...

Michael

-- 
=================================================================
Michael Nelson                            nelson@seahunt.imat.com
San Francisco, CA                            michaeln@csd.sgi.com

  "I don't want to achieve immortality through my work, I want   
   to achieve immortality by not dying."         - Woody Allen
   
================================================================= 


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

Date: Sat, 15 Feb 1997 04:41:30 GMT
From: jim@netcom.com
Subject: The Power And Peril Of Writing Perl CGI Code - Lan Times
Message-Id: <33053e76.299132479@netnews.worldnet.att.net>

The Power And Peril Of Writing Perl CGI Code - Lan Times 

Find this article at:

NewsLinx Daily Web News (2/14/97)

http://www.newslinx.com/


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

Date: Fri, 14 Feb 1997 23:02:47 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: using "$var" considered harmful?! (was Re: Q: opening a file RW without deleting it.)
Message-Id: <E5M80n.6JL@world.std.com>

Russell_Schulz@locutus.ofB.ORG (Russell Schulz) writes:

>I find it all much like warning people about escaping obscure punctuation
>on the right hands of regexes when they don't need to, or putting extra {}
>in C where they don't need to, or using () around conditionals in Pascal
>where you don't need to -- they just make maintenance that much easier,
>and lead to fewer surprises.

In school, a lot of my instructors were of the opinion, "when in
doubt, parenthesize". Since school, I've been hearing more arguments
against needless syntax, and I'm starting to side there.

If a programmer has a fairly good knowledge of the syntax of a
language, seeing things like parenthesis makes them think that
something unusual is going on, so they slow down reading just a bit
and analyze a little closer. When the parenthesis continually fall on
the regular precidence borders, different expressions are consulted
against each other, studied for whch goes first, when if the
parenthesis where dropped entirely, the precedence table burned on the
inside of the programmers skull would have been consulted instead.

On the other hand, the precidence in C is almost universally
considered "wrong" (It is on Dennis Ritchie's "If I could design C
over again." list) Pascal's precedence has similar problems if I
remember. Sometimes no matter how many times you see the same wrong
thing, it will never look right. Parenthesis around mathamatical and
boolean groups of expressions (and not within those groups unless
non-standard precidence is required) often strikes a good balance.

Interpolating variables into otherwise null strings probably more like
the first case, it does more harm (by raising the "VARIABLE
INTERPOLATION" flag) than good.

-- 
Andrew Langmead


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

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

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 V7 Issue 954
*************************************

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