[30830] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2075 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 24 03:09:44 2008

Date: Wed, 24 Dec 2008 00:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 24 Dec 2008     Volume: 11 Number: 2075

Today's topics:
        Chart::Gnuplot problem (Vicky Conlan)
    Re: Chart::Gnuplot problem <jimsgibson@gmail.com>
        new CPAN modules on Wed Dec 24 2008 (Randal Schwartz)
    Re: Perl 5 Completes Move to Git (Linux Today) <1usa@llenroc.ude.invalid>
    Re: Perl 5 Completes Move to Git (Linux Today) <tim@burlyhost.com>
    Re: Perl 5 Completes Move to Git (Linux Today) <1usa@llenroc.ude.invalid>
        Press a button <pod69@gmx.net>
    Re: Press a button <tim@burlyhost.com>
    Re: Press a button <wahab-mail@gmx.de>
    Re: Press a button <tadmc@seesig.invalid>
        regular expression like AND match <shay.rozen@gmail.com>
    Re: regular expression like AND match <peter@makholm.net>
    Re: regular expression like AND match <wahab-mail@gmx.de>
    Re: regular expression like AND match <jurgenex@hotmail.com>
    Re: regular expression like AND match <jimsgibson@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 23 Dec 2008 23:18:56 +0000 (UTC)
From: comps@riffraff.plig.net (Vicky Conlan)
Subject: Chart::Gnuplot problem
Message-Id: <girrl0$skp$1@magenta.plig.net>

I've got a little bit of a problem.  I'm not sure if I'm doing something
daft or if I've got a bad installation, but because I don't have any control
over the install I'm having trouble telling what is wrong.

So I've got a fairly simple script which I developed on a freeBSD machine
whilst I waited for the install on the machine at work.  It is fairly basic,
it has a couple of datasets, blah blah, then it draws some filled curves.
And it works fine.  (output: http://comps.org/fig/simple.png )

Then I tried exactly the same code on a solaris 10 zone and got the ever-
so-unhelpful error:

         "/tmp/2sp97fafGp/plot", line 1: undefined variable: noenhanced

There is no reference to noenhanced in /my/ code.  There are various bits
in the Gnuplot module that mention it, but noenhanced is the default, so I
don't see why it would work on one and not the other.

The only possibly relevant difference I can spot is that the working copy
uses gnuplot 4.2 patchlevel 3, the not-working uses 4.0 patchlevel 0

Any chance anyone has experienced this and can give me some subtle hints
about what could be the problem?  (thanks)

-- 


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

Date: Tue, 23 Dec 2008 17:34:25 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Chart::Gnuplot problem
Message-Id: <231220081734251582%jimsgibson@gmail.com>

In article <girrl0$skp$1@magenta.plig.net>, Vicky Conlan
<comps@riffraff.plig.net> wrote:

> I've got a little bit of a problem.  I'm not sure if I'm doing something
> daft or if I've got a bad installation, but because I don't have any control
> over the install I'm having trouble telling what is wrong.
> 
> So I've got a fairly simple script which I developed on a freeBSD machine
> whilst I waited for the install on the machine at work.  It is fairly basic,
> it has a couple of datasets, blah blah, then it draws some filled curves.
> And it works fine.  (output: http://comps.org/fig/simple.png )
> 
> Then I tried exactly the same code on a solaris 10 zone and got the ever-
> so-unhelpful error:
> 
>          "/tmp/2sp97fafGp/plot", line 1: undefined variable: noenhanced

Did you look in directory /tmp/2sp97fafGp for a file called plot? If
you look at the source of Chart::Gnuplot:

(<http://search.cpan.org/src/KWMAK/Chart-Gnuplot-0.06/lib/Chart/Gnuplot.
pm>),

it looks like it creates a file of that name containing commands to
gnuplot. Some of those commands, such as 'title' or 'set xlabel' can
contain the string 'noenhanced'. The question is why the string
'noenhanced' is being interpreted as a variable. While Chart::Gnuplot
probably attempts to clean up its files, your program may crash before
it has a chance to do so. So look in that directory and see if the
files are left around. If so, try sending the file to gnuplot and see
what happens.

You could also copy the source of Chart::Gnuplot and modify it so that
it does not clean up its files (remove 'CLEANUP => 1' or replace it
with 'CLEANUP => 0' ).

If you can get the file, does it have the string 'noenhanced' in line
1? If not, then you might have a line-ending problem, where the entire
file is being interpreted as a single line.

> There is no reference to noenhanced in /my/ code.  There are various bits
> in the Gnuplot module that mention it, but noenhanced is the default, so I
> don't see why it would work on one and not the other.

Sometimes a program will explicitly set a variable to its default
value, just for the sake of explicitness. Sometimes it is to override a
previous, non-default value. Several items can be 'enhanced', so you
don't know which one is being used unless you can inspect the plot
file.

> 
> The only possibly relevant difference I can spot is that the working copy
> uses gnuplot 4.2 patchlevel 3, the not-working uses 4.0 patchlevel 0

That is a pretty significant difference. Is there any chance you can
upgrade the non-working system to version 4.2?

To help you more, we would need to see some code and information about
versions: Perl, Chart::Gnuplot, etc.

-- 
Jim Gibson


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

Date: Wed, 24 Dec 2008 05:42:24 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed Dec 24 2008
Message-Id: <KCD96o.10Gs@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Acme-Madness-1.00
http://search.cpan.org/~uri/Acme-Madness-1.00/
----
Alien-Judy-0.05
http://search.cpan.org/~jjore/Alien-Judy-0.05/
A wrapper for installing the Judy library 
----
Apache-LangPrefCookie-1.03
http://search.cpan.org/~zeya/Apache-LangPrefCookie-1.03/
implant a language-preference given by cookie into httpd's representation of the Accept-Language HTTP-header. 
----
Apache2-Response-FileMerge-0.27
http://search.cpan.org/~wazzuteke/Apache2-Response-FileMerge-0.27/
Merge and include static files into a single file 
----
App-PPBuild-0.06
http://search.cpan.org/~exodist/App-PPBuild-0.06/
Perl Project Build System, The low-learning curve simple build system. 
----
App-PPBuild-0.07
http://search.cpan.org/~exodist/App-PPBuild-0.07/
Perl Project Build System, The low-learning curve simple build system. 
----
Astro-SpaceTrack-0.035
http://search.cpan.org/~wyant/Astro-SpaceTrack-0.035/
Retrieve orbital data from www.space-track.org. 
----
B-Generate-1.19
http://search.cpan.org/~rurban/B-Generate-1.19/
Create your own op trees. 
----
Badger-0.05
http://search.cpan.org/~abw/Badger-0.05/
Perl Application Programming Toolkit 
----
Business-DateTime-0.0.1
http://search.cpan.org/~stocks/Business-DateTime-0.0.1/
----
CPAN-Site-0.23
http://search.cpan.org/~markov/CPAN-Site-0.23/
CPAN.pm subclass for adding site local modules 
----
Config-Model-0.633
http://search.cpan.org/~ddumont/Config-Model-0.633/
Framework to create configuration validation tools and editors 
----
DateTime-Calendar-Liturgical-Christian-0.05
http://search.cpan.org/~marnanel/DateTime-Calendar-Liturgical-Christian-0.05/
----
DateTime-Calendar-Liturgical-Christian-0.10
http://search.cpan.org/~marnanel/DateTime-Calendar-Liturgical-Christian-0.10/
calendar of the church year 
----
Fey-ORM-0.16
http://search.cpan.org/~drolsky/Fey-ORM-0.16/
A Fey-based ORM 
----
HTML-Tabulate-0.32
http://search.cpan.org/~gavinc/HTML-Tabulate-0.32/
HTML table rendering class 
----
Judy-HS-0.08
http://search.cpan.org/~jjore/Judy-HS-0.08/
Library for creating and accessing a dynamic array, using an array-of-bytes as an Key and a word as a Value. 
----
KiokuDB-0.11
http://search.cpan.org/~nuffin/KiokuDB-0.11/
Object Graph storage engine 
----
KiokuDB-0.12
http://search.cpan.org/~nuffin/KiokuDB-0.12/
Object Graph storage engine 
----
KiokuDB-Backend-BDB-0.09
http://search.cpan.org/~nuffin/KiokuDB-Backend-BDB-0.09/
BerkeleyDB backend for KiokuDB. 
----
KiokuDB-Backend-DBI-0.03
http://search.cpan.org/~nuffin/KiokuDB-Backend-DBI-0.03/
DBI backend for KiokuDB 
----
KiokuDB-Backend-Files-0.01
http://search.cpan.org/~nuffin/KiokuDB-Backend-Files-0.01/
One file per object backend 
----
Mail-Log-Parse-1.0300
http://search.cpan.org/~dstaal/Mail-Log-Parse-1.0300/
Parse and return info in maillogs 
----
Mail-Log-Trace-1.0100
http://search.cpan.org/~dstaal/Mail-Log-Trace-1.0100/
Trace an email through the mailsystem logs. 
----
Markapl-0.06
http://search.cpan.org/~gugod/Markapl-0.06/
Markup as Perl 
----
Method-Cached-0.045_1
http://search.cpan.org/~boxphere/Method-Cached-0.045_1/
The return value of the method is cached to your storage 
----
Net-Twitter-2.00_01
http://search.cpan.org/~cthom/Net-Twitter-2.00_01/
Perl interface to twitter.com 
----
Padre-0.22
http://search.cpan.org/~smueller/Padre-0.22/
Perl Application Development and Refactoring Environment 
----
Padre-Plugin-HTML-0.06
http://search.cpan.org/~fayland/Padre-Plugin-HTML-0.06/
Padre and HTML 
----
Padre-Plugin-XML-0.03
http://search.cpan.org/~fayland/Padre-Plugin-XML-0.03/
Padre and XML 
----
Parallel-Depend-3.01
http://search.cpan.org/~lembark/Parallel-Depend-3.01/
Parallel::Depend 
----
SMS-Send-AU-MyVodafone-1.04
http://search.cpan.org/~adamk/SMS-Send-AU-MyVodafone-1.04/
An SMS::Send driver for the myvodafone.com.au website 
----
Simo-0.01_05
http://search.cpan.org/~kimoto/Simo-0.01_05/
Very simple framework for Object Oriented Perl. 
----
Task-KiokuDB-0.02
http://search.cpan.org/~nuffin/Task-KiokuDB-0.02/
Install KiokuDB and related modules. 
----
Template-Plugin-Komma-0.06
http://search.cpan.org/~uvoelker/Template-Plugin-Komma-0.06/
----
Tk-Win32RotLabel-0.4
http://search.cpan.org/~aqumsieh/Tk-Win32RotLabel-0.4/
A widget that allows rotated labels on the Win32 platform. 
----
URI-Template-Restrict-0.01
http://search.cpan.org/~masaki/URI-Template-Restrict-0.01/
restricted URI Templates handler 
----
WWW-PivotalTracker-0.1.0_5
http://search.cpan.org/~jhelwig/WWW-PivotalTracker-0.1.0_5/
Functional interface to Pivotal Tracker <http://www.pivotaltracker.com/> 
----
WWW-Rapidshare-Free-0.01
http://search.cpan.org/~haggai/WWW-Rapidshare-Free-0.01/
Automates downloading from Rapidshare.com and checking links for free users 
----
WWW-Scraper-ISBN-ISBNdb_Driver-0.06
http://search.cpan.org/~diberri/WWW-Scraper-ISBN-ISBNdb_Driver-0.06/
isbndb.com driver for WWW::Scraper::ISBN 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Tue, 23 Dec 2008 19:08:24 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl 5 Completes Move to Git (Linux Today)
Message-Id: <Xns9B7D8FD4FFE9Easu1cornelledu@127.0.0.1>

admin@ng2000.com wrote in news:489268799349932.Post@ithinknot.net:

> [snip URL ]

The actual announcement is at:

http://use.perl.org/articles/08/12/22/0830205.shtml

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Tue, 23 Dec 2008 11:48:31 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Perl 5 Completes Move to Git (Linux Today)
Message-Id: <jgb4l.3285$Uk3.1730@newsfe10.iad>

A. Sinan Unur wrote:

> admin@ng2000.com wrote in news:489268799349932.Post@ithinknot.net:
> 
>> [snip URL ]
> 
> The actual announcement is at:
> 
> http://use.perl.org/articles/08/12/22/0830205.shtml
> 
> Sinan
> 

That poster shows up in random tech and non tech groups all the time,
posting copied news articles to their own site/URL, to drive traffic to
their site.  It's unlikely they'll see or reply to the posts now.  They
have a habit of spamvertizing their site and moving onto the next
group.  Different from the normal spammer, in that they actually keep
the news on topic most of the time.  Of course, by only posting URL's
to their own site, though.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Tue, 23 Dec 2008 20:45:29 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl 5 Completes Move to Git (Linux Today)
Message-Id: <Xns9B7DA04A93807asu1cornelledu@127.0.0.1>

Tim Greer <tim@burlyhost.com> wrote in
news:jgb4l.3285$Uk3.1730@newsfe10.iad: 

> A. Sinan Unur wrote:
> 
>> admin@ng2000.com wrote in news:489268799349932.Post@ithinknot.net:
>> 
>>> [snip URL ]
>> 
>> The actual announcement is at:
>> 
>> http://use.perl.org/articles/08/12/22/0830205.shtml
>> 
>> Sinan
>> 
> 
> That poster shows up in random tech and non tech groups all the time,
> posting copied news articles to their own site/URL, to drive traffic
> to their site.  It's unlikely they'll see or reply to the posts now. 

That's what I assumed and therefore attempted to curtail any traffic he 
might derive from this post by posting the URL for original 
announcement.

Sinan


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Wed, 24 Dec 2008 00:07:43 +0100
From: pod <pod69@gmx.net>
Subject: Press a button
Message-Id: <49516f45$0$2634$91cee783@newsreader01.highway.telekom.at>

Hello,

I want to make a perl script that presses the Disconnect button of the 
below html code. I found some code but still I am not able to press the 
button. Can someone help me please with some code?

thx

<form name='PPPConn0' action='/cgi/b/is/' method='post'>
<input type='hidden' name='0' value=''>
<input type='hidden' name='1' value=''>
<input type='hidden' name='2' value='279867884'>
<hr>
<div class='contentitem'>
<table cellspacing='0' cellpadding='0'>
<tr><td class='icon' valign='top' width='100px'><img 
src='/images/cintgrxl.gif' alt='Internet Connection OK'></td>
<td class='data' valign='top'><table cellspacing='0' 
cellpadding='0'><tr><td align='left'><span 
class='itemtitle'>INTERNET</span></td><td align='right'><input 
type='button' name='13' value='Disconnect' 
onClick='submitForm(document.PPPConn0,13,0,"INTERNET","",0,"")' >
</td></tr>
<tr><td colspan='2'><input type='hidden' name='5' value="2">
<br><table cellspacing='0' cellpadding='0' width='100%'><tr><td 
width='40' valign='top'><img src='/images/bull__md.gif' alt=''></td><td 
valign='top'>
<span class='blocktitle'><a 
href="javascript:GoAndRemember('/cgi/b/is/_pppoa_/ov/', 
'name=INTERNET')">View more...</a></span><br>
</form>


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

Date: Tue, 23 Dec 2008 15:24:56 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Press a button
Message-Id: <cre4l.21564$X05.9447@newsfe03.iad>

pod wrote:

> Hello,
> 
> I want to make a perl script that presses the Disconnect button of the
> below html code. I found some code but still I am not able to press
> the button. Can someone help me please with some code?
> 
> thx
> 
> <form name='PPPConn0' action='/cgi/b/is/' method='post'>
> <input type='hidden' name='0' value=''>
> <input type='hidden' name='1' value=''>
> <input type='hidden' name='2' value='279867884'>
> <hr>


What sort of script would the user be connecting to/using?  In what way
are you attempting to "disconnect" them?  Just ending their active
session, preventing them from continuing with said session, or?  Sorry,
I didn't bother reading through the HTML source you had posted, as it
doesn't really offer the information needed to give you the best
answer.  Is this a Perl script in CGI, or some specific service?
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Wed, 24 Dec 2008 01:09:00 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Press a button
Message-Id: <girunr$5p6$1@mlucom4.urz.uni-halle.de>

pod wrote:
> I want to make a perl script that presses the Disconnect button of the 
> below html code. I found some code but still I am not able to press the 
> button. Can someone help me please with some code?
> 
> ...
> <input type='button' name='13' value='Disconnect' onClick='submitForm(document.PPPConn0,13,0,"INTERNET","",0,"")' />

What's the source code of this submitForm(...) part?

Regards

M.


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

Date: Tue, 23 Dec 2008 21:59:32 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Press a button
Message-Id: <slrngl3ct4.if6.tadmc@tadmc30.sbcglobal.net>

pod <pod69@gmx.net> wrote:

> I want to make a perl script that presses the Disconnect button of the 
> below html code. 


You misunderstand how this web stuff works.

The button is in the browser.

Perl programs do not run in a browser.

You cannot "press the button" in the browser from a Perl program.

What you _can_ do is to figure out what HTTP request the browser
sends when you click that button, then write a Perl program that
sends that same HTTP request.

If it were me, I'd set up the Web Scraping Proxy, click the
button in the browser, and then go see what wsp.pl has logged
for me.


> I found some code 


Let's see it. We cannot debug code that we cannot see.


> <input 
> type='button' name='13' value='Disconnect' 
> onClick='submitForm(document.PPPConn0,13,0,"INTERNET","",0,"")' >


Another way to figure out what request is being made is to figure
out what submitForm() does.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 23 Dec 2008 06:16:55 -0800 (PST)
From: ikeon <shay.rozen@gmail.com>
Subject: regular expression like AND match
Message-Id: <c592696c-258f-4f87-89eb-99647779cbda@r36g2000prf.googlegroups.com>

The case is that I need to search for a couple of strings in a line. I
don't know the order that they will be matched and I need them all to
be matched.
like if (string1|string2|string3) can find one of the strings (OR) , I
need it to match all of the strings (like AND) and again - I don't
know the order that they will appear.
I know how to do it if I will check the line 3 times in some loop, but
I need to know if it can be done in one regular expression.

Thanks,


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

Date: Tue, 23 Dec 2008 15:32:15 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: regular expression like AND match
Message-Id: <87zlinufm8.fsf@vps1.hacking.dk>

ikeon <shay.rozen@gmail.com> writes:

> I know how to do it if I will check the line 3 times in some loop, but
> I need to know if it can be done in one regular expression.

Yes, it can be done in a single regular expression, but why do you
need to do it in a single regular expression?

It's quite easy by using the correct look-around assertion, but I
guess it will be neither faster nor more maintainable than doing
something like:

   /pat1/ && /pat2/ && /pat3/


//Makholm


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

Date: Tue, 23 Dec 2008 17:30:31 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: regular expression like AND match
Message-Id: <gir3s6$qvb$1@mlucom4.urz.uni-halle.de>

ikeon wrote:
> The case is that I need to search for a couple of strings in a line. I
> don't know the order that they will be matched and I need them all to
> be matched.
> like if (string1|string2|string3) can find one of the strings (OR) , I
> need it to match all of the strings (like AND) and again - I don't
> know the order that they will appear.
> I know how to do it if I will check the line 3 times in some loop, but
> I need to know if it can be done in one regular expression.

This is nontrivial (imho) but can be done using
code assertions. The magic lies in setting a signal
denotig a specified hit during the match, e.g.
setting a bit in a word for each string matched.

Example:

  ...

  # what to find
  my @strings = qw'string1 string2 string3';

  # where to find
  my @lines = ('first line string1 ',
               'second line string1 string2 ',
               'third line string1 string2 string3 ');
  #expect: only line #3 shall match

  # make regex out of the search strings above (note the 'bts' thing)
  my $cnt = 0;
  my $reg = join '|', map $_.'(?{$bts|='.(1<<$cnt++).'})', @strings;

  # apply regex to the lines
  foreach my $line (@lines) {

    our $bts = 0;      # used within the regex engine
    use re 'eval';
    # ignore line unless the 'bits' 1,2,3 are in place
    next unless () = $line=~/$reg/g, $bts == 7;

    # we got one, do something ($bts was 7)
    print "$line\n"

  }

  ...

Regards

M.


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

Date: Tue, 23 Dec 2008 08:45:22 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: regular expression like AND match
Message-Id: <r952l4hiqnfpt1m5g1775v6hbufv0g8vqf@4ax.com>

ikeon <shay.rozen@gmail.com> wrote:
>The case is that I need to search for a couple of strings in a line. I
>don't know the order that they will be matched and I need them all to
>be matched.
>like if (string1|string2|string3) can find one of the strings (OR) , I
>need it to match all of the strings (like AND) and again - I don't
>know the order that they will appear.
>I know how to do it if I will check the line 3 times in some loop, but
>I need to know if it can be done in one regular expression.

Is there anything wrong with something like

	if (/string1/ or /string2/ or /string3/) {
		...
	}

resp.
	if (/string1/ and /string2/ and /string3/) {
		...
	}

jue


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

Date: Tue, 23 Dec 2008 09:28:42 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: regular expression like AND match
Message-Id: <231220080928428648%jimsgibson@gmail.com>

In article
<c592696c-258f-4f87-89eb-99647779cbda@r36g2000prf.googlegroups.com>,
ikeon <shay.rozen@gmail.com> wrote:

> The case is that I need to search for a couple of strings in a line. I
> don't know the order that they will be matched and I need them all to
> be matched.
> like if (string1|string2|string3) can find one of the strings (OR) , I
> need it to match all of the strings (like AND) and again - I don't
> know the order that they will appear.
> I know how to do it if I will check the line 3 times in some loop, but
> I need to know if it can be done in one regular expression.

In scalar context, 'grep {BLOCK} LIST' will return the number of times
BLOCK evaluates to true for the members of LIST. So you can put your
strings to be found in an array and do something like:

  my @strings = qw( string1 string2 string3 );
  my $string = '... string3 ... string1 ... string2 ...';
  my $n = grep { $string =~ /$_/ } @strings;
  if( $n == @strings ) {
    print "All strings found\n";
  }

This method has the advantage over the 

if( /string1/ && /string2/ && /string3/ ) { ... }

method in that you can vary the number of strings to be matched without
changing the matching code.

-- 
Jim Gibson


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 2075
***************************************


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