[10166] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3759 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 19 13:08:23 1998

Date: Sat, 19 Sep 98 10:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 19 Sep 1998     Volume: 8 Number: 3759

Today's topics:
    Re: ** Can I use 'split' here ? ** (David Adler)
    Re: Efficency Experiments (Ronald J Kimball)
        Enumerating Properties and Methods <JayGuerette@pobox.com>
    Re: ePerl Error in Here-Document String <samwang@freewwweb.com>
    Re: ePerl Error in Here-Document String <samwang@freewwweb.com>
    Re: ePerl Error in Here-Document String <bruceh@interaccess.com>
    Re: Help with file test operator problem (Ronald J Kimball)
    Re: Help with file test operator problem <samwang@freewwweb.com>
        Help!!!!! Compilation problems with mod_perl-1.15 <evonchen@mbox5.singnet.com.sg>
    Re: How do I implement perl with javascript or vice ver <samwang@freewwweb.com>
    Re: How do I implement perl with javascript or vice ver nospamno_adms1@cts.com
    Re: I need a script writen, can someone help me please (Tad McClellan)
        open2 question (Eric M Yeh)
    Re: Perl & Java - differences and uses (Larry Wall)
    Re: perl generated pages and frames... (brian d foy)
    Re: perl script error (Ronald J Kimball)
    Re: Problems running Perlshop on my NT cthomas@haleys.net
    Re: Ques: read data from pipe (Ronald J Kimball)
    Re: Ques: read data from pipe (Mike Collins)
    Re: Question about regex across multiple lines (Tad McClellan)
    Re: regular expression puzzle (Tad McClellan)
    Re: script: scriptMangle! <tchrist@mox.perl.com>
    Re: What does the + in print statement do? (Ronald J Kimball)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 19 Sep 1998 16:46:45 GMT
From: dha@panix.com (David Adler)
Subject: Re: ** Can I use 'split' here ? **
Message-Id: <6u0n5l$f9d@news1.panix.com>

On Fri, 18 Sep 1998 15:09:57 GMT, Patrick Timmins
<ptimmins@netserv.unmc.edu> wrote:

>In article <36023331.B4696981@email.sps.mot.com>,
>  r19610@email.mot.com wrote:
>...
>> Here's the scenario:
>>
>> I have defined :
>> $MY_DIR = "/usr/home"
>>
>> And I have a variable $TheFile = "/usr/home/new_file".
>>
>> How can I extract the filename, new_file from $TheFile? I tried to with :
>> split(/$MY_DIR/,$TheFile) but failed.
>> Any help is greatly appreciated.
>
>[snip]
>
>I probably wouldn't use split:
>
>$TheFile =~ s!.*/(.+)!$1!;

Or, if the string is in $_ :

$TheFile = m!.*/(.+)$!       #untested (remark just for completeness)

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
The perversity of the Universe tends towards a maximum.


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

Date: Sat, 19 Sep 1998 12:12:09 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Efficency Experiments
Message-Id: <1dflpzw.en3icy1nq4gs0N@bay1-204.quincy.ziplink.net>

Mooneer Salem <mooneer@earthlink.net> wrote:

> I was thinking
> that variable interpolization might be the bottleneck, so I tried to do
> as little of it as possible by using join statements whenever I needed
> to insert the contents of a variable into a string of printed text

Actually, join appears to be slightly but trivially slower than
double-quoted interpolation.

use Benchmark;

$five = 'a' x 5;
$fifteen = 'a' x 15;
$hundred = 'a' x 100;

timethese( 1000000, {
  inter =>
    sub { $_ = "abcdefgh $five ijklmno $fifteen pqrstuv $hundred wxyz"
},
  join  =>
    sub { $_ = join ' ', 'abcdefgh', $five, 'ijklmno', $fifteen,
                         'pqrstuv', $hundred, 'wxyz'
        },
});

Benchmark: timing 1000000 iterations of inter, join...
     inter: 12 secs (12.38 usr  0.00 sys = 12.38 cpu)
      join: 16 secs (15.00 usr  0.00 sys = 15.00 cpu)


Note that it took one million repetions to get 3 seconds of difference.


I don't see anything obvious that could make your program significantly
faster.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 19 Sep 1998 12:28:34 -0400
From: "Jay Guerette" <JayGuerette@pobox.com>
Subject: Enumerating Properties and Methods
Message-Id: <6u0m6l$98s@news-central.tiac.net>

If I call a method like this:

$foo->bar->method($args);

or access a property like this:

$foo->bar->{'prop'}="gnu";

how could I get a list of the methods and properties available to me from
this class?




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

Date: Sat, 19 Sep 1998 10:05:30 -0500
From: Sam Wang <samwang@freewwweb.com>
To: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: ePerl Error in Here-Document String
Message-Id: <3603C83A.CD856222@freewwweb.com>

it should also be noted that if the last line of your script is the end-here
marker, you have to add a new line after it. i think it has to do with the
end-document symbol.

"Matthew O. Persico" wrote:

> The end of the here do must match the beginning EXACTLY. The begining is
> "LOCATION_EOT".
> The end is "      LOCATION_EOT". Note the extra spaces! Leading and
> trailing spaces matter with here doc markers.
>
> Furthermore, since the error complains about AREA_EOT, I bet you have
> another here doc befor this that hs the same problem.



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

Date: Sat, 19 Sep 1998 10:05:16 -0500
From: Sam Wang <samwang@freewwweb.com>
To: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: ePerl Error in Here-Document String
Message-Id: <3603C82C.28F4A307@freewwweb.com>

it should also be noted that if the last line of your script is the end-here
marker, you have to add a new line after it. i think it has to do with the
end-document symbol.

"Matthew O. Persico" wrote:

> The end of the here do must match the beginning EXACTLY. The begining is
> "LOCATION_EOT".
> The end is "      LOCATION_EOT". Note the extra spaces! Leading and
> trailing spaces matter with here doc markers.
>
> Furthermore, since the error complains about AREA_EOT, I bet you have
> another here doc befor this that hs the same problem.



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

Date: Sat, 19 Sep 1998 11:09:10 -0500
From: Bruce Hodo <bruceh@interaccess.com>
Subject: Re: ePerl Error in Here-Document String
Message-Id: <3603C916.E21CA9A8@interaccess.com>

The spaces in front were the problem! Thanks to all who responded.

--
                 Bruce Hodo - Webmaster, GetAwayNetwork, Inc.
     ==Providing unique vacation information on the World Wide Web==
       For Villas, Resorts, Hotels, Air/Hotel Packages, Charter Airfares

                              And Now Offering Travel Auctions!
=============== Visit us at http://getawaynet.com ===============




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

Date: Sat, 19 Sep 1998 12:12:13 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Help with file test operator problem
Message-Id: <1dflq9f.s7y36ltilq8N@bay1-204.quincy.ziplink.net>

"Knight" <843943n34@knight_storm@usa.net.sprynet.com> wrote:

> $Dirname = ("C:/Daniel~1/song_b~1");
> 
> [open directory, read files into array...]
> 
> $testvar = 0;
> while ($testvar < $numberfiles)
>    {$file = @mainfiles[$testvar];
>     if (-f $file)

This tests $file in the currrent working directory, as documented.
Either change it to (-f "$Dirname/$file") or add chdir($Dirname) before
the loop.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 19 Sep 1998 11:04:16 -0500
From: Sam Wang <samwang@freewwweb.com>
Subject: Re: Help with file test operator problem
Message-Id: <3603D600.50025DE8@freewwweb.com>

from the looks of your c: you're on a windoze box. i strongly doubt that win32
perl will support file testing. i suppose you're trying to see if it's a
"shortcut" or not. you can do the same thing by testing if it's extension is
*.lnk

Knight wrote:

> There is something wrong with this script and I can't find it. What it is
> supposed to do is open a directory. Read the files in it. then if it is a
> normal file replace it's listing within the array I have the files stored in
> to "delete" for some reason it can not tell if the file is a file or not. I
> think there is something wrong with the file test operator, but I don't know
> for sure. Any help here is apprecieated. Thank you.



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

Date: Sun, 20 Sep 1998 00:54:54 +0800
From: Terence Wong <evonchen@mbox5.singnet.com.sg>
Subject: Help!!!!! Compilation problems with mod_perl-1.15
Message-Id: <3603E1DE.7D6A1E78@mbox5.singnet.com.sg>

Help!!!!!!!!!,

I keep getting "invalid option 'pentium' when I try to compile mod_perl
using the APXS options on my pentium pro machine. I'm quite new to this
so I don't know how to change the -mpentium option that I keep seeing
when I run make, to make it work. Could some guru out there me on this
and this is quite urgent actually so help!!!!!!!!!!!!!!!!!


Terence Wong



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

Date: Sat, 19 Sep 1998 08:28:52 -0500
From: Sam Wang <samwang@freewwweb.com>
Subject: Re: How do I implement perl with javascript or vice versa?
Message-Id: <3603B193.3239D8FF@freewwweb.com>

change your body tag to:

<BODY onUnload="logout.cgi">

(not sure that onUnload is the right event, as i havent' used javascript in
about 6 months)
however, this might not work, if they click close. you'll have to open up
javascript to open another window and go to that uri, to fix that.

however, this will not be transparent to the user, because when they leave, it
goes to somewhere they didn't expect to go. leaving the user confused. maybe,
you can have it open a new window, tell the window to go to logout.cgi and
then close the window. should be mostly transparent. though you might want
have the window say "logging out..." or something.

Chocolate wrote:

> I am not sure it this is the right group or not.  I want to set a cookie.
> I do this best with perl CGI but I know it can be done with JavaScript.
> The situation:
> I have this page that you have to log into.  There is a flat file with
> your username and a password that you made up along with some other
> information.  Once logged in your username is put into another file that
> says that you are online now.  It also gives you access to other parts of
> the page.  Now if you close the browser then your cookie is unset and you
> would have to log back in later but your name is still in the file that
> says that you are still here.  If you log out by clicking logout then you
> are removed from the file before you are logged out.  What I want to do is
> something like: onUnload logout.cgi.  How do I do this?
>
>               *         Web Page Designs          *
>             <  poohba@io.com  |  www.io.com/~poohba >
>               *           (919)599-5543           *
>



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

Date: Sat, 19 Sep 1998 16:24:01 GMT
From: nospamno_adms1@cts.com
Subject: Re: How do I implement perl with javascript or vice versa?
Message-Id: <3603d783.3801275@nntp.cts.com>

onUnload= will only execute JavaScript code.  If you absolutely what a
cgi script to remove the cookie, try something like:

<script language=JavaScript>
<!--
function logout() {
  if (logoutOK) {
    logoutWin = window.open("logout.cgi", "logout",
"toolbar=no,status=no,location=no");
  }
}
//-->
</script>

Then: <BODY onUnload="logout();">  Remember that all your links and
correct "exit" points should set logoutOK to false.

You will want to make sure that logout.cgi prints the JavaScript code
self.close to close this little window just created.

OR - You can check out http://www.dynamicsex.com/index.html for
JavaScript code to create/remove cookies. 


On Sat, 19 Sep 1998 08:28:52 -0500, Sam Wang <samwang@freewwweb.com>
wrote:

>change your body tag to:
>
><BODY onUnload="logout.cgi">
>
>(not sure that onUnload is the right event, as i havent' used javascript in
>about 6 months)
>however, this might not work, if they click close. you'll have to open up
>javascript to open another window and go to that uri, to fix that.
>
>however, this will not be transparent to the user, because when they leave, it
>goes to somewhere they didn't expect to go. leaving the user confused. maybe,
>you can have it open a new window, tell the window to go to logout.cgi and
>then close the window. should be mostly transparent. though you might want
>have the window say "logging out..." or something.
>
>Chocolate wrote:
>
>> I am not sure it this is the right group or not.  I want to set a cookie.
>> I do this best with perl CGI but I know it can be done with JavaScript.
>> The situation:
>> I have this page that you have to log into.  There is a flat file with
>> your username and a password that you made up along with some other
>> information.  Once logged in your username is put into another file that
>> says that you are online now.  It also gives you access to other parts of
>> the page.  Now if you close the browser then your cookie is unset and you
>> would have to log back in later but your name is still in the file that
>> says that you are still here.  If you log out by clicking logout then you
>> are removed from the file before you are logged out.  What I want to do is
>> something like: onUnload logout.cgi.  How do I do this?
>>
>>               *         Web Page Designs          *
>>             <  poohba@io.com  |  www.io.com/~poohba >
>>               *           (919)599-5543           *
>>
>



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

Date: Sat, 19 Sep 1998 10:42:03 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: I need a script writen, can someone help me please
Message-Id: <bcj0u6.vo1.ln@metronet.com>

Gareth Hall (guruchoc@bigpond.com) wrote:

: Can somone write a script for me. 


   If you state how much the job pays you will likely get
   better responses to job offers...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 19 Sep 1998 15:49:46 GMT
From: emy457@merle.acns.nwu.edu (Eric M Yeh)
Subject: open2 question
Message-Id: <6u0jqq$kgh@news.acns.nwu.edu>

Hi, I'm having trouble with the open2 command.  I need to have my perl
program write and read from a command such as 'bc'.  I tried this code but
the program never stops...

use IPC::Open2;
use Symbol;

$WTR = gensym();
$RDR = gensym();
$pid = open2($RDR, $WTR, 'bc');
print $WTR "2+2";
$line = <$RDR>


then I try to print $line ...

anyhelp is appreciated...
thanks



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

Date: 19 Sep 1998 09:23:28 -0700
From: larry@kiev.wall.org (Larry Wall)
Subject: Re: Perl & Java - differences and uses
Message-Id: <6u0lq0$ij1@kiev.wall.org>

In article <bOPM1.856$Ge.2187567@ptah.visi.com>,
George Reese  <borg@imaginary.com> wrote:
>I have already stated that freedom has no place in programming.  Now
>you may disagree with it, and I have certainly provided support for
>that assertion.  It therefore makes no sense to come back with freedom
>to counter that argument.  You may want to try explaining why a
>programmer should have freedom.

Because the programmer knows what he or she wants to optimize for, and
the language designer doesn't.  Plus, it's more fun.

Dink Thifferent.

Larry


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

Date: Sat, 19 Sep 1998 12:14:44 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: perl generated pages and frames...
Message-Id: <comdog-ya02408000R1909981214440001@news.panix.com>
Keywords: from just another new york perl hacker

In article <6tuirn$6so$1@minus.oleane.net>, "GaRgL" <gargl@worldnet.net> posted:

>how can i print to different frames using perl ?
>
>i'm currently reading the faq...

see the CGI Meta FAQ.  after reading the FAQ, further questions should
be directed to a newsgroup that discusses CGI.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers needs volunteers! <URL:http://www.pm.org/to-do.html>


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

Date: Sat, 19 Sep 1998 12:12:15 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: perl script error
Message-Id: <1dflqhd.1hs4a9gv01likN@bay1-204.quincy.ziplink.net>

CA Aspiras <saints@jps.net> wrote:

> i have this perl counter script that seems to work fine but somehow
> server logs show a failure with this error message:
> 
>   Premature end of script headers
> 
> any ideas on what's causing that error message?

Nope...  But splitting a string just so you can print it one character
at a time is rather silly.  Especially when you copy each character to
another variable first.  Also, you're not actually printing HTML text,
so your content-type is incorrect.

Anyway, check your server's error logs.

> [...]

> print "Content-type: text/html\n\n";

> [...]

> @nums = split(//, $count); 
> 
> foreach $num (@nums) {
>   $display = "$num";
>    print $display;
> }                       

print $count;

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 19 Sep 1998 16:14:32 GMT
From: cthomas@haleys.net
Subject: Re: Problems running Perlshop on my NT
Message-Id: <3603d737.3787009@nntp.infoave.net>

I'm running PerlShop on a UNIX box and have received the same message.
Check your dir where the cgi is located. Look for a file called
PageHits.lock, If it's there delete it. Every now and then this file
appears on my system. When it's there the cgi won"t output. My ISP
says he's not generating the file. I sent a message to PerlShops
writers about what could cause this but didn't receive any info. Any
help on this from you GURUs out there would be appreciated. 

On Sat, 19 Sep 1998 15:05:24 +0200, Eyal Moshe <eyal@infomall.co.il>
wrote:

>Hi all..
>
>I'm having problems running Perlshop, free shopping cart software, on my
>
>system. When I run it I get the message:
>
>    "Invalid Transmission #3 received from: 209.88.180.2
>     If your connection was interrupted, you must Enter the shop from
>the beginning again."
>
>209.88.180.2 is my IP.. I'm not sure if I've configured the perl script
>and especially the paths well. If anyone works with Perlshop in NT and
>can help me or maybe even send me his configuration file (actually the
>perl script itself) I'll be VERY thankful.
>
>If you know some other free shopping cart for NT, I'd love to hear about
>
>it.
>
>Thanks in advance,
>
>Eyal Moshe
>



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

Date: Sat, 19 Sep 1998 12:12:17 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Ques: read data from pipe
Message-Id: <1dflqoy.1lspg5pr63nobN@bay1-204.quincy.ziplink.net>

Mike Collins <mike@w3z.com> wrote:

> Can someone offer a simple example of a perl script receiving a
> message piped from .procmailrc? 
 
:0 fhw
| perl -pe 's/^(From: .*\n)/$1Old-$1/mi;'

This finds a From: header and duplicates it as Old-From:

> I assume perl reads from STDIN and am curious about which perldoc to
> reference and what module(s) to use, if any.

I guess that depends on what you want the perl script to do...

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 19 Sep 1998 16:43:05 GMT
From: mike@w3z.com (Mike Collins)
Subject: Re: Ques: read data from pipe
Message-Id: <3603dbc7.47931336@news.110.net>

>> simple example message piped from .procmailrc 

>:0 fhw
>| perl -pe 's/^(From: .*\n)/$1Old-$1/mi;'
>This finds a From: header and duplicates it as Old-From:

Desired result - parse an email to update a web page.

Final question on this (maybe?), can the procmail start 
my perl script after saving the msg (IN.txt).

 .procmailrc recipe
------------------
:0:
* ^Subject:.*test
$HOME/httpd/cgi-bin/TEST/IN.txt   # works
echo "perl $path/test.pl"         # doesn't

perl test
---------
#! /usr/bin/perl5
open (RESULTS, '>/path/cgi-bin/TEST/OUT.txt');
open (DATA, '/path/cgi-bin/TEST/IN.txt') || die;
while (<DATA>){print RESULTS;}



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

Date: Sat, 19 Sep 1998 10:32:40 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Question about regex across multiple lines
Message-Id: <oqi0u6.sm1.ln@metronet.com>

Michael D Lewis (mlewis@nmia.com) wrote:
:    I'm trying to change an ASCII file using a RE in a perl script.  Since 
: it has not been successful, I've tried to reduce the file format down to
: the parts that are giving me a problem.  If I can find a solution for this
: test format, I should be able to convert it back up into the real format.  


   A most wonderful appoach to getting your problem solved!

   You are a clever poster (because you 1) made small example, 
   2) showed input,  3) showed desired output)

   Oh that more posters would take your example and greatly increase
   their chances of getting a usable answer...



:    Here's an example of the input file:
:    
: <3> 1 fred
: barney
: <5> 2 wilma
: betty

:    And here's what it should look like on the output:
:    
: <3> 4 fred
: barney
: <5> 10 wilma
: betty


: Notes:
:         1) The number following the bracketed number should become the
:            value of the bracketed number plus 1 added to a running total
:            ( which starts at 0 ).  So 0+3+1=4 and 4+5+1=10

:         2) Many lines of text can exist between "barney" and "<5>". 
:         
: So my program would do a "m/<(\d)>/" . If it was successful, it would do
: the math on the number it would find, and do a 
: "s/<(\d)>/\s+\d+\s+/<$1> $newvalue /".
: This worked until I found out that the input file could also look like:

: <3>
:  1 fred
: barney
: <5> 2 wilma
: betty

:    To span multiple lines I added the line $/ = ".\n"; to the program.

   Well that isn't going to help at all.

   The description of the $/ variable (in the 'perlvar' man page) says:

      "Remember: the value of $/ is a string, not a regexp."

   Since you don't have any lines that end with a dot (or maybe you do?), 
   you slurp the entire file in on the first <> input operator...

   Which is (kinda) good. You need slurping (or more complicated
   code to "collect" records) to handle that second input form.

   See code below for the usual way of doing slurping.


: Now I can't seem to connect the values I find with the values I need to replace.
: It seems like the /g option on the m/ operator will walk through the
: string one find at a time, where the /g option on the s/ operator will
: not.


   I don't think I'm following you there...


:   Can this conversion be done using REs?  


   Yep.


: Or do I have to brute force my
: way thru the file?


   Nope.


   This seems to work for me. Hope it helps:


-----------------------------------
#!/usr/bin/perl -w

undef $/;
$_=<DATA>;  # slurp whole file into a single scalar, not so good
            # if the data file is truly large...

$total = 0;

s/(<(\d+)>\s+)\d+/
  $total += $2 + 1;

  "$1$total";
 /ge;

print;


__DATA__
<3>
 1 fred
barney
rubble
(best friend)
<5> 2 wilma
betty
rubble
(friend's wife)
-----------------------------------


   An alternative solution would be to "normalize" the second form
   to look like the first form (bracketed and to-be-replaced nums
   on the same line).



: Thanks,

   You're welcome.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 19 Sep 1998 09:12:18 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regular expression puzzle
Message-Id: <24e0u6.sc1.ln@metronet.com>

Ralph Brands (brinton@unixg.ubc.ca) wrote:
: I have a text file in which some characters are coded by bounding them
: with "&" and ";" so that:

: &ae;
: &d;
: &t;         are all characters

: w&ae;nt
: &ae;llum    are both words


: If I want to search for strings that contain both of two regular
: expressions as separate words I do the substitution below. But this
: matches string1 only if there is more than 1 space between "&ae;nt" and
: "dog"! 


   You don't say whether or not you understand why it works that way.

   In case you don't, see below for why it works that way  ;-)


: Any suggestions as to how I can change the regular expression
: substitution to get around this would be gratefully appreciated,


   A zero-width lookahead assertion will help for the "trailing"
   boundary condition.



: #!/usr/bin/perl

   You should always enable warnings in all of you perl programs.

   Really.

   #!/usr/bin/perl -w


: $firstregexp = "&ae;nt";
: $secondregexp = "dog"; 
:    
: $string1 = "a string with &ae;nt dog and other words";
: $string2 = "a string with &ae;nt and dog";

: #to match separate words only if new word boundary condition is met:

: $firstregexp =~ s/$firstregexp/(^|[^a-z&;])$firstregexp([^a-z&;]|\$)/gi;
                                                          ^^^^^^^^
: $secondregexp =~ s/$secondregexp/(^|[^a-z&;])$secondregexp([^a-z&;]|\$)/gi; 
                                      ^^^^^^^^

   Those two places require matching a character. When put together
   as in your patmat below, you need two characters there for it
   to match.


$firstregexp =~ s/$firstregexp/(^|[^a-z&;])$firstregexp(?=[^a-z&;]|\$)/gi;
                                                        ^^
$secondregexp =~ s/$secondregexp/(^|[^a-z&;])$secondregexp(?=[^a-z&;]|\$)/gi;
                                                           ^^

   Use zero-width lookahead assertion. Now, when combined, you only
   need one character.

   Perl 5.005 has added lookbehind assertions, which should help with
   the "leading" boundary condition. I don't have it yet, so I
   cannot try it...


: print "$firstregexp\n";
: print "$secondregexp\n";

: print "LINE 1 MATCHES\n" if ($string1 =~ /($firstregexp).*($secondregexp)/); 
: print "LINE 2 MATCHES\n" if ($string2 =~ /($firstregexp).*($secondregexp)/);


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 19 Sep 1998 16:28:32 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: script: scriptMangle!
Message-Id: <6u0m3g$br4$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    cberry@cinenet.net (Craig Berry) writes:
:Or shroud the source, or compile it, or...  All these techniques are real,
:practical solutions to real-world problems.

Evil is as evil does.

:OK, let me ask you, as I have Tom:  Do you lock your front door at home?

I don't usually do this, but here you go: I never want to read
anything from you again.  

*PLONK*

--tom
-- 
You want it in one line?  Does it have to fit in 80 columns?   :-)
                --Larry Wall in <7349@jpl-devvax.JPL.NASA.GOV>


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

Date: Sat, 19 Sep 1998 12:12:20 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: What does the + in print statement do?
Message-Id: <1dflqxs.1iq4vzv1i2pqxgN@bay1-204.quincy.ziplink.net>

MS <webmaster@hubeicorp.com> wrote:

> Can anyone tell me the difference in this
> 
> open (FILE ,"+>>file.txt");
> 
> and this
> 
> open (FILE ,">>file.txt");
> 
> That + sign is in already in some code I'm modifying -- it works, but
> I can't find that + sign mentioned in any of the books I have,

Probably because you're looking for it under 'print' (see subject), and
it actually occurs in 'open'.

+ is mentioned under 'open' in the manpages and in Programming Perl.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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 3759
**************************************

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