[23123] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5344 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 11 18:05:48 2003

Date: Mon, 11 Aug 2003 15:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 11 Aug 2003     Volume: 10 Number: 5344

Today's topics:
        Apache::ASP Package (PM) refresh problem <islaw@adexec.com>
    Re: Apache::ASP Package (PM) refresh problem <islaw@adexec.com>
    Re: connecting to a database (with no web server) <member32241@dbforums.com>
    Re: connecting to a database (with no web server) <glex_nospam@qwest.net>
        forking and ending a CGI process <robyoung68@yahoo.com>
    Re: forking and ending a CGI process <NOSPAM@bigpond.com>
    Re: How to find the info from documentation quickly?? (Tad McClellan)
    Re: How to find the info from documentation quickly?? <tzz@lifelogs.com>
    Re: How to find the info from documentation quickly?? <wksmith@optonline.net>
    Re: Little help with While loop please? <nobull@mail.com>
        Perl faq and posted to newsgroup but not to perldoc.com (Upstart)
    Re: Perl faq and posted to newsgroup but not to perldoc (Tad McClellan)
        perl GetShortPathName! (sangeetha)
    Re: perl GetShortPathName! <pinyaj@rpi.edu>
    Re: Perl Math Syntax <abigail@abigail.nl>
    Re: Print - format /  presentation question <mothra@nowhereatall.com>
    Re: Regex Head Scratcher <drumspoorly@reachone.net>
        Regular expressions, parsing data file (Brian Andrus)
    Re: Regular expressions, parsing data file <noreply@gunnar.cc>
    Re: Regular expressions, parsing data file <krahnj@acm.org>
    Re: Script displays in dos window, not browser <islaw@adexec.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 11 Aug 2003 14:13:18 -0700
From: "Islaw" <islaw@adexec.com>
Subject: Apache::ASP Package (PM) refresh problem
Message-Id: <bh90tj$vfbl4$1@ID-196529.news.uni-berlin.de>

I'm using Apache:ASP version 2.53, Perl 5.6.1, RH 7.3, Apache/1.3.23 (with
mod_perl and FP 5.0)

ASP Perl works quite nicely, but I noticed that if I create a user made .pm
file package (note: it was in same dir as the .asp file), it reads it and
uses it's code, but I noticed that when making changes to the .pm file, it
doesn't always refresh to show them. What's really strange is that as I keep
refreshing the asp page (to show the same results again and again - the asp
file is called from a .htm file wit ha form in it), sometimes it shows the
newest version (the output is generate by a function in the pm file calling
$main::Response:write), sometimes an older one, and sometimes it gives me an
error that it could not find the "new" function (I have one as the
constructor) and that it could not be loaded.

Its as if it's fighting with the cache weather or not to display the current
or an old version. Is there any way around this? I looked around the apache
asp website docs but nothing about this was turned up. Perldoc wasn't much
help either as it doesn't deal with ASP Perl.

Thanks for any help.

--
Islaw




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

Date: Mon, 11 Aug 2003 14:16:53 -0700
From: "Islaw" <islaw@adexec.com>
Subject: Re: Apache::ASP Package (PM) refresh problem
Message-Id: <bh914a$vhbp7$1@ID-196529.news.uni-berlin.de>

Islaw wrote:
> I'm using Apache:ASP version 2.53, Perl 5.6.1, RH 7.3, Apache/1.3.23
> (with mod_perl and FP 5.0)

[...]
> output is generate by a function in the pm file calling
> $main::Response:write), sometimes an older one, and sometimes it


Small correction, that should read $main::Response->Write(). I also tried
using print() btw too.

--
Islaw




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

Date: Mon, 11 Aug 2003 15:09:23 +0000
From: dominant <member32241@dbforums.com>
Subject: Re: connecting to a database (with no web server)
Message-Id: <3224950.1060614563@dbforums.com>


I downloaded the source, as it is mentioned, oracle.pm. What can i do
with that?

--
Posted via http://dbforums.com


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

Date: Mon, 11 Aug 2003 12:57:09 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: connecting to a database (with no web server)
Message-Id: <vMQZa.23$1f4.26441@news.uswest.net>

dominant wrote:
> I downloaded the source, as it is mentioned, oracle.pm. What can i do
> with that?

First, read the README file.  It should answer how to test and install 
the module.  Then install it.




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

Date: Mon, 11 Aug 2003 18:15:21 GMT
From: Rob Young <robyoung68@yahoo.com>
Subject: forking and ending a CGI process
Message-Id: <Z2RZa.340165$o86.150401@news1.central.cox.net>

Hi;
I spent about 4 hours searching through newsgroups, faqs, and O'reilly 
books with various odd-smelling desert animals on the cover. I found 
that this question has been asked A LOT, but none of the answers worked 
for me. I'm posting this in hopes it will help someone else, and to 
solicit comments on why the other methods did not work and whether this 
is the best way.

The problem: You are batching e-mails to a large number of subscribers, 
and you don't want the CGI script to wait until the mail process 
finishes before completing the page.

Many people wrote to just put
   $|=1;
at the top of your script. I am using the Mail::Bulkmail module, so
I tried this down near the end of the routine after the $bulk object had 
been defined.

$|=1;
print "";
print qq(Thank you.... );
$bulk->bulkmail() or die $bulk->error;

and the script hesitated for 17 seconds before printing the thankyou 
statement, just as it did without the buffer change. Mail was delivered OK.

Then I tried forking it like this:

if (my $pid = fork) {
   print qq(Thank you.... );
} else {
   die "cannot fork: $!" unless defined $pid;
   $bulk->bulkmail() or die $bulk->error;
}

No difference.

Then I tried closing STDOUT

$|=1;
print "";
if (my $pid = fork) {
   print qq(Thank you.... );
   close(STDOUT);close(STDERR);
} else {
   die "cannot fork: $!" unless defined $pid;
   $bulk->bulkmail() or die $bulk->error;
}

That got instant results, but no mail was sent. I'm guessing
that Apache terminated the process when STDOUT closed?

Some people wrote to write the entire script to a new file and
then use system() to call it, but this script needs to be portable,
and some CGI wrappers don't allow system() calls or backticks.

This is what finally worked:

$|=1;
print "";
if (my $pid = fork) {
   print qq(Thank you.... );
   kill("KILLBUFFER"=>$$);
} else {
   die "cannot fork: $!" unless defined $pid;
   $bulk->bulkmail() or die $bulk->error;
}

Comments or suggestions welcome.

Rob








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

Date: Tue, 12 Aug 2003 08:04:56 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: forking and ending a CGI process
Message-Id: <bh93ua$vknao$1@ID-202028.news.uni-berlin.de>

"Rob Young" <robyoung68@yahoo.com> wrote in message
news:Z2RZa.340165$o86.150401@news1.central.cox.net...
> Hi;
> I spent about 4 hours searching through newsgroups, faqs, and O'reilly
> books with various odd-smelling desert animals on the cover. I found
> that this question has been asked A LOT, but none of the answers worked
> for me. I'm posting this in hopes it will help someone else, and to
> solicit comments on why the other methods did not work and whether this
> is the best way.
>
> The problem: You are batching e-mails to a large number of subscribers,
> and you don't want the CGI script to wait until the mail process
> finishes before completing the page.

Use the "daemonzie" routine
http://www.perldoc.com/perl5.8.0/pod/perlipc.html


gtoomey




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

Date: Mon, 11 Aug 2003 08:03:03 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to find the info from documentation quickly??
Message-Id: <slrnbjf507.int.tadmc@magna.augustmail.com>

hou <dhouremove@rohan.sdsu.edu> wrote:

>      How can I get the information I need quickly from
>      the perl documentation?? 


By grep()ing it for terms relevant to the current problem.


>      For example:
>        Now I am confused with function "glob" and "*INPUT = *STDIN".


The term "glob" is overloaded, you have 2 different uses of the term there.

The glob() function is a "filename glob".

The *SOMETHING syntax is a "type glob".


>      Would you please share some experiences with me?


(wrapped)

   http://groups.google.com/groups?as_umsgid=
      slrna1mmj4.bj1.tadmc%40tadmc26.august.net


One further hint, try searching for "Glob" rather than "glob".

Finding your term in a "headline", or at the beginning of a
sentence, increases the chances of that being a good place to look.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 11 Aug 2003 13:26:27 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to find the info from documentation quickly??
Message-Id: <4nekzs6r7g.fsf@lockgroove.bwh.harvard.edu>

On 11 Aug 2003, dhou@rohan.sdsu.edu wrote:

Simon Taylor <simon@unisolve.com.au> wrote:
>        Actually, my question was "what is the first(,second,and
>        third...)  thing I need to do in order to find info quickly
>        using perldoc?".
> 
>        You are an experienced programmer, so you know where to
>        locate information you need.  But I am just a newbie, how do
>        I know I should look for File::Glob?

Read the Perl FAQs that come with Perl (perldoc -q "keyword" searches
them; you can see the top list with "perldoc perlfaq").  They're
called FAQs for a reason - you will almost certainly go "a-ha!" a few
times while you're reading them, and they will spark your interest in
other directions.

Ted


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

Date: Mon, 11 Aug 2003 19:15:55 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: How to find the info from documentation quickly??
Message-Id: <LXRZa.42811$_R5.12753316@news4.srv.hcvlny.cv.net>


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbjf507.int.tadmc@magna.augustmail.com...
> hou <dhouremove@rohan.sdsu.edu> wrote:
>
> >      How can I get the information I need quickly from
> >      the perl documentation??
>
>
> By grep()ing it for terms relevant to the current problem.
>
--snip--

On my windows system, I use tcgrep from the "Perl Cookbook".  I modified
it to do the file glob that Unix shells do for you.  This is a very
powerful version of grep, but it is not very fast.  Any other
suggestions?

Bill




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

Date: 11 Aug 2003 17:42:46 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Little help with While loop please?
Message-Id: <u9y8y0xi0p.fsf@wcl-l.bham.ac.uk>

allistah@hotmail.com (Allister) writes:

> Subject: Re: Little help with While loop please?

"Little help with ... please"  contains no information.  It only
serves to annoy.

How about:

Subject: Preserving information from previous iteration of a loop


> I'm trying to take in a log file via stdin from my mail server.  The
> mail server will output anywhere from 5-11 lines in the log file per
> message.  I need to parse these lines looking for the first word of
> FROM so I can get the senders email address.  Then I need to walk a
> few more lines down looking for BDAT or DATA to get the size of the
> message where 3333 is the message size below.  Then just output these
> two out to STDOUT on the same line.

OK just do it then.  
 
> I've currently got a while (<>) {} loop to parse things one at a time,
> but I can't figure out how to make it go down a few more lines looking
> for the BDAT or DATA part without losing the information from the line
> where I got the FROM data.

When you encounter the FROM line then put the value in a scalar
variable (e.g. $from).  When later, you need that information,
retrieve it from the variable.

Make sure the variable $from is declared outside the loop.

This has nothing much to do with Perl - the technique is prety much
the same in any procedural programming language.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 11 Aug 2003 06:57:21 -0700
From: stimonyhall@netscape.net (Upstart)
Subject: Perl faq and posted to newsgroup but not to perldoc.com
Message-Id: <79516caa.0308110557.15aad199@posting.google.com>

Hi

I found the following faq useful after searching google:

FAQ: How do I use MIME to make an attachment to a mail message? 

It talks about MIME::Lite and how to use it. My problem is that this
faq is not on perldoc.com; and the email faq does not have a link for
the source. After looking around, I found it on www.cpan.org.
Question/request:

- Why does the perldoc.com site and the cpan.org site differ?

- in the netnews, maybe include a link to the webpage that has the
source? Maybe it does, but google does not pick it up.

JIM


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

Date: Mon, 11 Aug 2003 10:30:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl faq and posted to newsgroup but not to perldoc.com
Message-Id: <slrnbjfdk9.jso.tadmc@magna.augustmail.com>

Upstart <stimonyhall@netscape.net> wrote:

> I found the following faq useful after searching google:


Why search google when it is already on your very own hard disk?

   perldoc -q MIME


> FAQ: How do I use MIME to make an attachment to a mail message? 
> 
> My problem is that this
> faq is not on perldoc.com


No, the problem is that you are looking on the 'net instead of
looking at the docs that you installed along with perl itself.  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 11 Aug 2003 08:53:37 -0700
From: sangeetha_b@india.com (sangeetha)
Subject: perl GetShortPathName!
Message-Id: <4fde56d3.0308110753.75ca8870@posting.google.com>

Hi, 

I'm facing problem in GetShortPathName function.

 Case 1:
    use Win32;
    $shortpath = Win32::GetShortPathName( "c:/program files" );
    print "$shortpath";

    output: "c:/PROGRA~1"
       
 Case 2:

  $x= "c:/program Files/GNU/Case Study 1";
  $shortpath = Win32::GetShortPathName($x);
  print "$shortpath";
   
     output:  (nothing)

Actualy, i'm facing problem in creating the file(s) under the long
directory (including the blank space) name.. so i've writen the above
testcase to test whether the "GetShortPathName" is working or not !!

Can any one help me in this regard?

Thanks in advance

Sangeetha B


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

Date: Mon, 11 Aug 2003 12:06:18 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: sangeetha <sangeetha_b@india.com>
Subject: Re: perl GetShortPathName!
Message-Id: <Pine.SGI.3.96.1030811120434.182897A-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 11 Aug 2003, sangeetha wrote:

>    $shortpath = Win32::GetShortPathName( "c:/program files" );
>    print "$shortpath";
>
>    output: "c:/PROGRA~1"

I'm sure the "c:/program files" directory exists...

>  $x= "c:/program Files/GNU/Case Study 1";
>  $shortpath = Win32::GetShortPathName($x);
>  print "$shortpath";
>   
>     output:  (nothing)

 ... but it sounds like THAT directory doesn't exist, and you're trying to
generate the shortpath name for it.

>Actualy, i'm facing problem in creating the file(s) under the long
>directory (including the blank space) name.. so i've writen the above
>testcase to test whether the "GetShortPathName" is working or not !!

If this is the case, perhaps the GetShortPathName() function merely
determines what the OS has already assigned as its short name; perhaps it
can't produce a short name for a non-existent directory.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: 11 Aug 2003 13:06:44 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl Math Syntax
Message-Id: <slrnbjf573.q6t.abigail@alexandra.abigail.nl>

Louis Erickson (wwonko@rdwarf.com) wrote on MMMDCXXVI September MCMXCIII
in <URL:news:bgoh3c$4gt$1@holly.rdwarf.com>:
!!  Uri Guttman <uri@stemsystems.com> wrote:
!! :>>>>> "EJR" == Eric J Roode <REMOVEsdnCAPS@comcast.net> writes:
!!  
!! :   EJR> Why is that "better"?  For a simple variable increment, I would
!! :   EJR> say that it's just a matter of style.  I can't see any real
!! :   EJR> difference between
!!  
!! :   EJR>     $opened = $opened + 1;
!! :   EJR>     $opened += 1;
!! :   EJR>     $opened++;
!!  
!! : run them under the benchmark module. report your results back here. 
!!  
!!  Hmm.  Uri, why do you say this?  It sounds like you are suggesting that
!!  the fastest one is the best.  I thought you were one of the "Whatever is
!!  the easiest to read, write, and maintain is best" school, and felt that
!!  premature optimiazion was evil.
!!  
!!  Not to say that all optimization is evil, or that it's not interesting to
!!  know.
!!  
!!  Myself, I think that $v = $v + 1; may be clearest for someone new to
!!  programming, although I find it a bit wordy.  I prefer $v++, but I'm from C,
!!  and expected to like that kind of confusion.  I like pointers, too, so
!!  that should tell you what kind of a pervert I really am.  =)
!!  
!!  You've got me curious now, so I've gone ahead and fired up Benchmark as you
!!  suggested.  The results are not what I expected, either.  (This is just
!!  another example of why you should always use timings, rather than what
!!  you expect.)
!!  
!!  If the program I've written isn't a good demonstration of this, please
!!  let me know.  I've seen several discussions with Benchmark go by where
!!  the program used for timing wasn't right, which gave bogus values.
!!  
!!  [Note: I have reformatted this output slightly to make it fit 80 columns.]
!!  
!!  wwonko@holly:~ $ perl
!!  use strict;
!!  use warnings;
!!  use Benchmark;
!!  
!!  our $counter;
!!  
!!  Benchmark::cmpthese(10000000, {
!!          plusequ=>sub {$counter += 1},
!!          plusone=>sub {$counter = $counter +1},
!!          plusplus=>sub {$counter++}
!!  });
!!  Benchmark: timing 10000000 iterations of plusequ, plusone, plusplus...
!!     plusequ:  2 wallclock secs ( 1.41 usr +  0.02 sys =  1.43 CPU)
!!  	@ 6993006.99/s (n=10000000)
!!     plusone:  4 wallclock secs ( 2.98 usr + -0.02 sys =  2.96 CPU)
!!  	@ 3378378.38/s (n=10000000)
!!    plusplus:  2 wallclock secs ( 1.63 usr + -0.02 sys =  1.61 CPU)
!!  	@ 6211180.12/s (n=10000000)
!!                Rate  plusone plusplus  plusequ
!!  plusone  3378378/s       --     -46%     -52%
!!  plusplus 6211180/s      84%       --     -11%
!!  plusequ  6993007/s     107%      13%       --
!!  wwonko@holly:~ $ 
!!  
!!  Running this again got me:
!!  
!!                Rate  plusone plusplus  plusequ
!!  plusone  3412969/s       --     -44%     -56%
!!  plusplus 6097561/s      79%       --     -22%
!!  plusequ  7812500/s     129%      28%       --
!!  
!!  Obviously, my system load influenced this somewhat.
!!  
!!  If I'm reading this correctly, it looks like $v += 1; is fastest, closely
!!  followed by $v++.  I would have expected the reverse.  And, $v = $v +1; is
!!  the slowest, as I would have expected.
!!  
!!  Interestingly, I get different results if I use a 'my' variable rather
!!  than an 'our' variable.  One is lexical and the other isn't, correct?
!!  
!!  wwonko@holly:~ $ perl
!!  use strict;
!!  use warnings;
!!  use Benchmark;
!!  
!!  Benchmark::cmpthese(10000000, {
!!          plusequ=>sub {my $counter = 0; $counter += 1},
!!          plusone=>sub {my $counter = 0; $counter = $counter +1},
!!          plusplus=>sub {my $counter = 0; $counter++}
!!  });
!!  Benchmark: timing 10000000 iterations of plusequ, plusone, plusplus...
!!     plusequ:  4 wallclock secs ( 5.07 usr + -0.01 sys =  5.06 CPU)
!!  	@ 1976284.58/s (n=10000000)
!!     plusone:  6 wallclock secs ( 5.07 usr +  0.01 sys =  5.08 CPU)
!!  	@ 1968503.94/s (n=10000000)
!!    plusplus:  6 wallclock secs ( 5.07 usr + -0.12 sys =  4.95 CPU)
!!  	@ 2020202.02/s (n=10000000)
!!                Rate  plusone  plusequ plusplus
!!  plusone  1968504/s       --      -0%      -3%
!!  plusequ  1976285/s       0%       --      -2%
!!  plusplus 2020202/s       3%       2%       --
!!  wwonko@holly:~ $
!!  
!!  And again...
!!  
!!  	      Rate  plusone  plusequ plusplus
!!  plusone  1930502/s       --      -1%      -3%
!!  plusequ  1956947/s       1%       --      -2%
!!  plusplus 1988072/s       3%       2%       --
!!  
!!  These are not the results I expected, but they seem to be reasonably stable.


I'm not at all surprised by the last results. The time needed to call a sub,
enter a block, initialize a variable, and leave the block (which requires
Perl to do all the bookkeeping associated with '$counter' going out of 
scope) vastly dominates adding 1 to the variable, by whatever method.
So, the differences you measure are small.

Here are some other results:

#!/usr/bin/perl

use strict;
use warnings;

use Benchmark qw 'cmpthese';

our ($c1, $c2, $c3);

cmpthese -1 => {
    plusone  =>  '$::c1 = $::c1 + 1',
    plusplus =>  '$::c2 ++',
    plusequ  =>  '$::c3 += 1',
};

__END__
Benchmark: running plusequ, plusone, plusplus for at least 1 CPU seconds...
   plusequ:  2 wallclock secs ( 1.00 usr +  0.00 sys =  1.00 CPU)
             @  5794762.00/s  (n=5794762)
   plusone:  1 wallclock secs ( 1.18 usr +  0.00 sys =  1.18 CPU)
             @  3588672.03/s  (n=4234633)
  plusplus: -1 wallclock secs ( 1.08 usr +  0.00 sys =  1.08 CPU)
             @ 12312183.33/s (n=13297158)
               Rate  plusone  plusequ plusplus
plusone   3588672/s       --     -38%     -71%
plusequ   5794762/s      61%       --     -53%
plusplus 12312183/s     243%     112%       --

-- 
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:


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

Date: Mon, 11 Aug 2003 07:11:22 -0700
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: Print - format /  presentation question
Message-Id: <3f365519$1@usenet.ugs.com>

Hi Eric,

[snipped]

> The way I wrote it was an exact copy, modulo whitespace, of what Mothra
> posted.  I happen to have respect for Mothra, based on his or her posts
> here, which is why I didn't post a flame, and why I felt that nothing
> more than "careful" plus an error dump was needed for Mothra to
> understand that s/he should have known better than to post a quick
> solution without making sure that it was correct.
>
I do my best to test before I post. (I like all who have been here for some
time
have made the mistake of posting bad code and have paid the price
for it) In this case I did test. Here is what I did.

use strict;
use warnings;
use diagnostics;

print "*" x10 . "\n";

I did not post the first 3 lines (stupid me) If I had it would
have been clearer for all.

> However, I made the mistake of thinking that whitespace didn't matter to
> Mothra's solution.  It does.

The whitespace does make a difference! (I did the same thing ie:
left out the white space and received the same error that you did)
That is why I added the whitespaces.

> Not because of precedence, not because of
> associativity, but because "10." is interpreted as a number, rather than
> a number plus the concatenation operator.  My mistake, not Mothra's; mea

No problem :)

Mothra




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

Date: Mon, 11 Aug 2003 14:40:28 -0700
From: Steve May <drumspoorly@reachone.net>
Subject: Re: Regex Head Scratcher
Message-Id: <vjg2np3a0fusae@corp.supernews.com>

mooseshoes wrote:
> All:
> 
> I've run into a dark alley with a regex and could use some assistance.
> 
> I have a list of keywords as keys in a hash (eg. %keywords) and I am looking
> at each key to see if it can be matched in a string.

<SNIP>

Other posts dealt with the issues you were having with your regular
expression.

However, one thing to keep in mind is that your list of key words
gets longer, using a regex to match against them in the string
gets less and less efficient.  In other words, the regex approach
does not seem to scale well IF you are searching for multiple words.

It usually only takes a limited number of key words (two in some cases)
to iterate through before it becomes more effecient to split the string
and then check the resulting list against the keywords hash.

Something like:

my @list = split /\s/, $string;

for( @list ){
   $keywords{$_} or next;
   print "found one ( $_ )\n";
}

You might want to benchmark whatever you come up with and see for
yourself.

What I've found is that variations of the above will benchmark about
the same and regex time increases dramatically as the number of keys
increases.

Just a thought....

s.



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

Date: 11 Aug 2003 09:41:17 -0700
From: batman@thundermail.com (Brian Andrus)
Subject: Regular expressions, parsing data file
Message-Id: <ae9a7893.0308110841.56a5aa6b@posting.google.com>

Ok, no surprise, but I have having trouble figuring out regular
expressions.

I want to parse a data file in perl to find a mac address of a
particular IP.
The format of the data file is something like:

lease 192.168.1.199 {
  starts 1 2003/8/11 00:00:67;
  ends 1 2003/08/11 00:05:67;
  hardware ethernet 00:c0:f7:43:c0:25;
  client-hostname "brad";
}

So I only want to return the line hardware ethernet IF it is enclosed
within the lease 192.168.1.199 set. Also that set shows up multiple
times in the data file, so I want the first occurence, which isn't so
bad. What is getting me is how do I return the first occurence of a
line AFTER the first occurence of something else?

I imagine it may be easier to just right a subroutine to turn on a
flag, but I was hoping there was a one-liner type thing to do, so I
could learn something new.

Brian Andrus


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

Date: Mon, 11 Aug 2003 18:57:55 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regular expressions, parsing data file
Message-Id: <bh8hvt$v2q7g$1@ID-184292.news.uni-berlin.de>

Brian Andrus wrote:
> The format of the data file is something like:
> 
> lease 192.168.1.199 {
>   starts 1 2003/8/11 00:00:67;
>   ends 1 2003/08/11 00:05:67;
>   hardware ethernet 00:c0:f7:43:c0:25;
>   client-hostname "brad";
> }
> 
> So I only want to return the line hardware ethernet IF it is
> enclosed within the lease 192.168.1.199 set. Also that set shows up
> multiple times in the data file, so I want the first occurence,
> which isn't so bad. What is getting me is how do I return the first
> occurence of a line AFTER the first occurence of something else?

One way: By making it non-greedy:

     ($return) = /lease 192\.168\.1\.199.+?(hardware[\w :]+);/s;
-----------------------------------------^-------------------^

Please read about greediness at perlre:
http://www.perldoc.com/perl5.8.0/pod/perlre.html#Regular-Expressions

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Mon, 11 Aug 2003 21:19:07 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Regular expressions, parsing data file
Message-Id: <3F380843.CC2F5D25@acm.org>

Brian Andrus wrote:
> 
> Ok, no surprise, but I have having trouble figuring out regular
> expressions.
> 
> I want to parse a data file in perl to find a mac address of a
> particular IP.
> The format of the data file is something like:
> 
> lease 192.168.1.199 {
>   starts 1 2003/8/11 00:00:67;
>   ends 1 2003/08/11 00:05:67;
>   hardware ethernet 00:c0:f7:43:c0:25;
>   client-hostname "brad";
> }
> 
> So I only want to return the line hardware ethernet IF it is enclosed
> within the lease 192.168.1.199 set. Also that set shows up multiple
> times in the data file, so I want the first occurence, which isn't so
> bad. What is getting me is how do I return the first occurence of a
> line AFTER the first occurence of something else?


$/ = '}';
while ( <> ) {
    print "$1\n" if ?192\.168\.1\.199\s*{[^}]*hardware ethernet\s*([[:xdigit:]:]+)?i;
    }



John
-- 
use Perl;
program
fulfillment


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

Date: Mon, 11 Aug 2003 14:22:22 -0700
From: "Islaw" <islaw@adexec.com>
Subject: Re: Script displays in dos window, not browser
Message-Id: <bh91ej$uf5k6$1@ID-196529.news.uni-berlin.de>

Alan C. wrote:
>
> http://perl.about.com/cs/beginningperl/
>
> http://perl.about.com/cs/intermediateperl/

That is a nice site indeed, but I do find it amusing that they have
ads/links for spam removal on a site thats just full of them ;p

--
Islaw




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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5344
***************************************


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