Re: RegExp matching over multiple lines

2008-10-21 Thread Chris Wagner
Hi.  Ur problem probably has to do with how ur eating the HTML file.  A
regex with /s needs the entire file in one variable.  If u do a line by line
with  it won't work since u won't have everything in one var.  Give
this a try.

$file = join "", ;
@divmatches = $file =~ m/]*>(.+?)<\/div>/sg;

As others have said using one of the HTML modules is the best way to handle
general parsing, but in trivial cases simple regex's like this are fine.


At 09:46 AM 10/21/2008 -0700, Andy Postulka wrote:
>I'm having difficulty using RegExp to match/extract across several lines in
an HTML file.
>
>I want to match and extract everything between a pair of HTML tags. 
>This Match/Extraction can occur over multiple lines in an HTML file.
> 
>I'm using the following RegExp to test the HTML file for a Match/Extraction
>
>/(.*?)<\/div>/s


--
REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
"...ne cede malis"

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: RegExp matching over multiple lines

2008-10-21 Thread Brian Raven
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Andy Postulka
Sent: 21 October 2008 17:47
To: perl-win32-users@listserv.ActiveState.com
Subject: RegExp matching over multiple lines

> Hi to everyone,
> 
> First off I hope I'm posting this to the right Mailing list. 
> If not, please forgive me in advance. I just started using ActivePerl
> 
> I'm having difficulty using RegExp to match/extract across several
lines in an HTML file.
> 
> I want to match and extract everything between a pair of HTML tags. 
> This Match/Extraction can occur over multiple lines in an HTML file.
>  
> I'm using the following RegExp to test the HTML file for a
Match/Extraction
> 
> /(.*?)<\/div>/s
> 
> 
> Here is my Test HTML file.
> 
> Case #1
>  Some text  Number 1
>  
> 
> Case #2
>  Some text  Number 2 
> 
> Case #3 
> 
>   Some text  Number 3
> 
> 
> This only match that occurs is "Case #2" when the Tag pair occurs on
the same line.
> So that  tells me the RegExp works for a single line. 
> 
> When I split the Tag Pair over more that one line (Case # 1 & Case #3)
it fails to match. 
> Since the "." does not match the "new line" characters I've used the
"s" modifier, but that does not  seem to 
> work
> 
> I've tried using different combinations of the "s" & "m" modifiers
which didn't seem to help any
> I've also tried to "chomp()" each line to strip the new line
characters from each line before applying the 
> RegExp and use the different combination of the "sm" modifiers. That
didn't work either.

That regular expression works fine on that data for me. There must be
something you are not telling us. It would have helped if you posted
real code, e.g.


use strict;
use warnings;

local $/;
my $data = ;
while ($data =~ /(.*?)<\/div>/sg) {
print "Found '$1'\n";
}
__DATA__
Case #1
 Some text  Number 1
 

Case #2
 Some text  Number 2 

Case #3 

  Some text  Number 3



However, the best advice that can give is that regular expressions are
not a good tool to parse HTML, but HTML::Parser is. Or better still one
of the modules that is derived from it, e.g. HTML::TokeParser or
HTML::TreeBuilder.

HTH

-- 
Brian Raven 

---
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: RegExp matching over multiple lines

2008-10-21 Thread Tobias Hoellrich
Andy - do yourself a favor and don't try it manually. This problem has been 
solved by a number of publicly available modules already. Take a look at 
HTML::Parser (or HTML::PullParser) for example, which offers extraction of 
content between opening and closing tags.

Hope this helps
  Tobias


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andy Postulka
Sent: Tuesday, October 21, 2008 10:47 AM
To: perl-win32-users@listserv.ActiveState.com
Subject: RegExp matching over multiple lines

Hi to everyone,

First off I hope I'm posting this to the right Mailing list.
If not, please forgive me in advance. I just started using ActivePerl

I'm having difficulty using RegExp to match/extract across several lines in an 
HTML file.

I want to match and extract everything between a pair of HTML tags.
This Match/Extraction can occur over multiple lines in an HTML file.

I'm using the following RegExp to test the HTML file for a Match/Extraction

/(.*?)<\/div>/s


Here is my Test HTML file.

Case #1
 Some text  Number 1


Case #2
 Some text  Number 2 

Case #3

  Some text  Number 3


This only match that occurs is "Case #2" when the Tag pair occurs on the same 
line.
So that  tells me the RegExp works for a single line.

When I split the Tag Pair over more that one line (Case # 1 & Case #3) it fails 
to match.
Since the "." does not match the "new line" characters I've used the "s" 
modifier, but that does not  seem to work

I've tried using different combinations of the "s" & "m" modifiers which didn't 
seem to help any
I've also tried to "chomp()" each line to strip the new line characters from 
each line before applying the RegExp and use the different combination of the 
"sm" modifiers. That didn't work either.

I can't figure out what I'm doing wrong.
I'm using Active Perl 5.10.0 on a Windows XP computer.

Any help to solve this problem will be greatly appreciated.

Andy

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: regexp question

2004-12-15 Thread eric-amick


> I seem to be missing a piece of the puzzleI want to define a character > class ([]) > with atoms to (not) match involve negative look-ahead assertions.but no > joy. > > I am reading a stream of text that may contain the two segments \\n and \" > > I want to define a regexp that will match up to the first of either of > these. 
I would suggest a slightly different approach, especially since you apparently might not have either sequence. Try
 
if ($str =~ /n|\\"/)
{
$mytext = substr($str, 0, $-[0]);
# do whatever with $mytext
}
 
The arrays @- and @+ contain the starting and ending offsets within a string of the portion successfully matched by a regular _expression_; the 0th elements refer to the whole regex, and other elements to the portions captured by parentheses.
 
See perlvar in the docs and the description of substr under perlfunc.
 
--Eric AmickColumbia, MD
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: regexp question

2004-12-15 Thread Christopher Hahn
 
Hello all,

Thank you for the time.  I guess that this foray into lookaround assertions
was bust.  ;0) I am using Parse::RecDescent and I realized that I could use
the
order of Rules to ensure that if I *wasn't* looking at either a \\n or a \"
then I would have a bare \ that a simple Production could deal with.

Thanks (Mr $) to all!

chahn

-Original Message-
From: $Bill Luebkert [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 14, 2004 7:37 PM
To: Christopher Hahn
Cc: [EMAIL PROTECTED]
Subject: Re: regexp question

Christopher Hahn wrote:

> $Bill,
> 
> The (?: ) construct may be non-capturing, but it does eat text from 
> the buffer (sic)
> 
> ...and, besides, when I ran it I saw this:
> =
> 1: asd asdf adf asd \n asd adf
> 2: asd asdf adf asd \n asd adf
> 3: asd asdf adf asd  asd adf
> =
> 
> where I need to see something like this:
> =
> 1: asd asdf adf asd
> 2: asd asdf adf asd \n asd adf
> 3: asd asdf adf asd  asd adf
> 4: asd asdf adf asd  asd adf " ad dasf \n dsaf 
> =
> 
> i.e. \n should pass through, where \\n or \" should not.

Does a non-greedy match help (also - I was missing an escape or two on the
\\n):

foreach (
  '1: asd asdf adf asd n asd adf \" ad dasf dsaf ',
  '2: asd asdf adf asd \n asd adf \" ad dasf dsaf ',
  '3: asd asdf adf asd  asd adf \" ad dasf n dsaf ',
  '4: asd asdf adf asd  asd adf " ad dasf \n dsaf ',
  ) {
if (/^(.*?)(?:n|\\")/) {
print "$1\n";
}
}

> 
> What about trying something like:
> 
>   $strval =~ m/^(( [^\\] | \\ (?! \\ (?= n)) | \\ (?! \") )*)/x;
> 
> which (or so I think ;0) collects as many characters from the 
> beginning of $str that meet these conditions (bs = backslash):
> =
>1) not a bs
> or 2) a bs that is *not* followed by a ( bs that *is* followed by a n 
> ) or 3) a bs that is *not* followed by a "
> =

-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic
http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: regexp question

2004-12-14 Thread $Bill Luebkert
Christopher Hahn wrote:

> $Bill,
> 
> The (?: ) construct may be non-capturing, but it does eat text from the
> buffer (sic)
> 
> ...and, besides, when I ran it I saw this:
> =
> 1: asd asdf adf asd \n asd adf 
> 2: asd asdf adf asd \n asd adf 
> 3: asd asdf adf asd  asd adf 
> =
> 
> where I need to see something like this:
> =
> 1: asd asdf adf asd 
> 2: asd asdf adf asd \n asd adf 
> 3: asd asdf adf asd  asd adf 
> 4: asd asdf adf asd  asd adf " ad dasf \n dsaf 
> =
> 
> i.e. \n should pass through, where \\n or \" should not.

Does a non-greedy match help (also - I was missing an escape
or two on the \\n):

foreach (
  '1: asd asdf adf asd n asd adf \" ad dasf dsaf ',
  '2: asd asdf adf asd \n asd adf \" ad dasf dsaf ',
  '3: asd asdf adf asd  asd adf \" ad dasf n dsaf ',
  '4: asd asdf adf asd  asd adf " ad dasf \n dsaf ',
  ) {
if (/^(.*?)(?:n|\\")/) {
print "$1\n";
}
}

> 
> What about trying something like:
> 
>   $strval =~ m/^(( [^\\] | \\ (?! \\ (?= n)) | \\ (?! \") )*)/x;
> 
> which (or so I think ;0) collects as many characters from the beginning of
> $str that
> meet these conditions (bs = backslash):
> =
>1) not a bs
> or 2) a bs that is *not* followed by a ( bs that *is* followed by a n )
> or 3) a bs that is *not* followed by a "
> =

-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: regexp question

2004-12-14 Thread Christopher Hahn

$Bill,

The (?: ) construct may be non-capturing, but it does eat text from the
buffer (sic)

...and, besides, when I ran it I saw this:
=
1: asd asdf adf asd \n asd adf 
2: asd asdf adf asd \n asd adf 
3: asd asdf adf asd  asd adf 
=

where I need to see something like this:
=
1: asd asdf adf asd 
2: asd asdf adf asd \n asd adf 
3: asd asdf adf asd  asd adf 
4: asd asdf adf asd  asd adf " ad dasf \n dsaf 
=

i.e. \n should pass through, where \\n or \" should not.


What about trying something like:

  $strval =~ m/^(( [^\\] | \\ (?! \\ (?= n)) | \\ (?! \") )*)/x;

which (or so I think ;0) collects as many characters from the beginning of
$str that
meet these conditions (bs = backslash):
=
   1) not a bs
or 2) a bs that is *not* followed by a ( bs that *is* followed by a n )
or 3) a bs that is *not* followed by a "
=

Am I making any sense?  ;0)

Thank you for taking the time in any case!

Christopher

-Original Message-
From: $Bill Luebkert [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 14, 2004 1:41 PM
To: Christopher Hahn
Cc: [EMAIL PROTECTED]
Subject: Re: regexp question

Christopher Hahn wrote:

> Hey,
> 
> I seem to be missing a piece of the puzzleI want to define a 
> character class ([]) with atoms to (not) match involve negative 
> look-ahead assertions.but no joy.
> 
> I am reading a stream of text that may contain the two segments \\n and \"
> 
> I want to define a regexp that will match up to the first of either of 
> these.
> 
> ...ie. something like ([^]*) where the character class is just the two 
> sequences above.
> 
> ...but they are not characters at all, but strings, and so I wonder 
> how to approach this.
> 
> Question: how best to do something to set
> 
>$1 == every character in the string up to and not including the 
> first of either a \\n or a \"
> 
> That is all. (something like $strval =~ m/ (.* (?! \\ (?= \" | \\ (?= 
> n) ) )
> )/x;)
> 
> I am going to use this regexp in a Parse::RecDescent Production, and 
> have other Rules to deal with the \\n and \" strings.
> 
> I am banging on this and will report when something good comes out of 
> it, but please do chime in with any "best practices" that suggest 
> themselves to you.

I assume that \\n is actually 3 characters and not a newline.
It should be as simple as :

use strict;

foreach (
  '1: asd asdf adf asd \\n asd adf \" ad dasf dsaf ',
  '2: asd asdf adf asd \n asd adf \" ad dasf dsaf ',
  '3: asd asdf adf asd  asd adf \" ad dasf \\n dsaf ',
  '4: asd asdf adf asd  asd adf " ad dasf \n dsaf ',
  ) {
if (/^(.*)(?:n|\\")/) {
print "$1\n";
}
}

__END__


-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic
http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: regexp question

2004-12-14 Thread $Bill Luebkert
Christopher Hahn wrote:

> Hey,
> 
> I seem to be missing a piece of the puzzleI want to define a character
> class ([])
> with atoms to (not) match involve negative look-ahead assertions.but no
> joy.
> 
> I am reading a stream of text that may contain the two segments \\n and \"
> 
> I want to define a regexp that will match up to the first of either of
> these.
> 
> ...ie. something like ([^]*) where the character class is just the two
> sequences above.
> 
> ...but they are not characters at all, but strings, and so I wonder how to
> approach this.
> 
> Question: how best to do something to set 
> 
>$1 == every character in the string up to and not including the first of
> either a \\n or a \"
> 
> That is all. (something like $strval =~ m/ (.* (?! \\ (?= \" | \\ (?= n) ) )
> )/x;)
> 
> I am going to use this regexp in a Parse::RecDescent Production, and have
> other Rules to 
> deal with the \\n and \" strings.
> 
> I am banging on this and will report when something good comes out of it,
> but please do
> chime in with any "best practices" that suggest themselves to you.  

I assume that \\n is actually 3 characters and not a newline.
It should be as simple as :

use strict;

foreach (
  '1: asd asdf adf asd \\n asd adf \" ad dasf dsaf ',
  '2: asd asdf adf asd \n asd adf \" ad dasf dsaf ',
  '3: asd asdf adf asd  asd adf \" ad dasf \\n dsaf ',
  '4: asd asdf adf asd  asd adf " ad dasf \n dsaf ',
  ) {
if (/^(.*)(?:n|\\")/) {
print "$1\n";
}
}

__END__


-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: regexp!

2004-06-19 Thread Ted Schuerzinger
$Bill Luebkert graced perl with these words of wisdom:

> Ananthan S wrote:
> 
>> 
>>  hi.,
>> 
>>  what is regular expression ? And in hash variable can get a key
>>  through its value..? 
> 
> You can't get a key from a value as easily as you can get a value
> from a key, but if your values are unique, you could do it be
> reversing the hash.  If you have multiple keys with the same
> value, your results will be partially correct at best.

$Bill:

Can't you sort the keys of the hash and run through them with a foreach 
loop, checking the value of the key?  I'm thinking of a snippet along the 
lines of the following (adapted from a script of mine, but untested in 
this context):



foreach (sort {uc($a) cmp uc($b)} keys %hash) {
   if ($hash{$_} == 0) {  # if looking for a numerical value
 do_some_stuff_here;
 }  #ifclose
   if ($hash{$_} =~ /regex/) { #if looking for a string
   do_some_stuff_here;  
 } #ifclose
} #forclose
  


-- 
Ted Schuerzinger 
The way I see it, you raised three children who could knock out and hog-
tie a perfect stranger, you must be doing *something* right.
Marge Simpson, 
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: regexp!

2004-06-18 Thread $Bill Luebkert
Ananthan S wrote:

> 
>   hi.,
> 
>   what is regular expression ? And in hash variable can get a key
>   through its value..?

You can't get a key from a value as easily as you can get a value
from a key, but if your values are unique, you could do it be
reversing the hash.  If you have multiple keys with the same
value, your results will be partially correct at best.

perlfunc manpage :

reverse LIST
In list context, returns a list value consisting of the elements of
LIST in the opposite order. In scalar context, concatenates the
elements of LIST and returns a string value with all characters in
the opposite order.

print reverse <>;   # line tac, last line first

undef $/;   # for efficiency of <>
print scalar reverse <>;# character tac, last line tsrif

This operator is also handy for inverting a hash, although there are
some caveats. If a value is duplicated in the original hash, only
one of those can be represented as a key in the inverted hash. Also,
this has to unwind one hash and build a whole new one, which may
take some time on a large hash, such as from a DBM file.

%by_name = reverse %by_address; # Invert the hash

>   Please clear me.. and point out me some good website on perl
>   programs and faqs

You have all you need in the docs that come with Perl.  I like
to combine the base pods into a manual and search it using vim.
There's a script on my Tripod site to create a large manual from
the pods.

See the following man pages and you'll become an expert in no time:

perlrequick Perl regular expressions quick start
perlretut   Perl regular expressions tutorial
perlre  Perl regular expressions, the rest of the story
perlreref   Perl regular expressions quick reference


-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Regexp needed

2002-10-17 Thread Carl Jolley
On Mon, 14 Oct 2002 [EMAIL PROTECTED] wrote:

> Hi, i have a file like this:
> .
> p167   bt1sqtf4 2720  1055adelevin  2002-10-14 11:21
> p130   bt1sqtf4 1753  520 aginer2002-10-14 10:33
> p143   bt1sqtf4 1658  518 alchippe  2002-10-14 10:30
> p144   bt1sqtf4 1777  663 amaragou  2002-10-14 10:33
> p175   bt1sqtf4 2976  1148ascatola  2002-10-14 11:30
> p176   bt1sqtf4 3039  1164bceillie  2002-10-14 11:36
> p135   bt1sqtf4 1224  503 blegrand  2002-10-14 10:07
> p122   bt1sqtf4 4692  616 CAPTMA1   2002-10-14 09:53
> p163   bt1sqtf4 2577  813 cfrancoi  2002-10-14 11:14
> p154   bt1sqtf4 2200  914 chtuffre  2002-10-14 10:54
> p146   bt1sqtf4 1848  589 cky   2002-10-14 10:35
> p116   bt1sqtf4 4476  581 cvanlath  2002-10-14 09:42
> ..
>
> How can i extract the 5 parameter ie the PID and put all in a an array?
> Thanks for your precious help.
>

I would code it like:

while() {
  push(@pid,(split(/\s+/,$_))[4]);
}

 [EMAIL PROTECTED] 
 All opinions are my own and not necessarily those of my employer 


___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Regexp needed

2002-10-14 Thread Krishna, Hari

Should be fairly simple...

You can split it using the space concept...

($p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8) = split(/\s+/,$_);

So $p5 has the fifth element and you can do what ever you want with that.

Or you can use the array (@arr_extract) and do the same.



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 14, 2002 10:29 AM
To: [EMAIL PROTECTED]
Subject: RE: Regexp needed


Hi, i have a file like this:
.
p167   bt1sqtf4 2720  1055adelevin  2002-10-14 11:21
p130   bt1sqtf4 1753  520 aginer2002-10-14 10:33
p143   bt1sqtf4 1658  518 alchippe  2002-10-14 10:30
p144   bt1sqtf4 1777  663 amaragou  2002-10-14 10:33
p175   bt1sqtf4 2976  1148ascatola  2002-10-14 11:30
p176   bt1sqtf4 3039  1164bceillie  2002-10-14 11:36
p135   bt1sqtf4 1224  503 blegrand  2002-10-14 10:07
p122   bt1sqtf4 4692  616 CAPTMA1   2002-10-14 09:53
p163   bt1sqtf4 2577  813 cfrancoi  2002-10-14 11:14
p154   bt1sqtf4 2200  914 chtuffre  2002-10-14 10:54
p146   bt1sqtf4 1848  589 cky   2002-10-14 10:35
p116   bt1sqtf4 4476  581 cvanlath  2002-10-14 09:42
..

How can i extract the 5 parameter ie the PID and put all in a an array?
Thanks for your precious help.

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

CONFIDENTIALITY NOTICE:
This e-mail message, including all attachments, is for the sole use of the
intended recipient(s) and may contain confidential and privileged
information. You may NOT use, disclose, copy or disseminate this
information.  If you are not the intended recipient, please contact the
sender by reply e-mail immediately.  Please destroy all copies of the
original message and all attachments. Your cooperation is greatly
appreciated. 
Columbus Regional Hospital
2400 East 17th Street 
Columbus, Indiana 47201
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Regexp needed

2002-10-14 Thread Stovall, Adrian M.

Assuming you put each line in a variable called $line...

@columns = split($line);

Pretty simple, eh?  @columns will have 8 elements (0-7) based on the
data you provided.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Sent: Monday, October 14, 2002 10:29 AM
To: [EMAIL PROTECTED]
Subject: RE: Regexp needed


Hi, i have a file like this:
.
p167   bt1sqtf4 2720  1055adelevin  2002-10-14 11:21
p130   bt1sqtf4 1753  520 aginer2002-10-14 10:33
p143   bt1sqtf4 1658  518 alchippe  2002-10-14 10:30
p144   bt1sqtf4 1777  663 amaragou  2002-10-14 10:33
p175   bt1sqtf4 2976  1148ascatola  2002-10-14 11:30
p176   bt1sqtf4 3039  1164bceillie  2002-10-14 11:36
p135   bt1sqtf4 1224  503 blegrand  2002-10-14 10:07
p122   bt1sqtf4 4692  616 CAPTMA1   2002-10-14 09:53
p163   bt1sqtf4 2577  813 cfrancoi  2002-10-14 11:14
p154   bt1sqtf4 2200  914 chtuffre  2002-10-14 10:54
p146   bt1sqtf4 1848  589 cky   2002-10-14 10:35
p116   bt1sqtf4 4476  581 cvanlath  2002-10-14 09:42
..

How can i extract the 5 parameter ie the PID and put all in a an array?
Thanks for your precious help.

___
Perl-Win32-Users mailing list [EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Regexp needed

2002-10-14 Thread JGONCALV

Hi, i have a file like this:
.
p167   bt1sqtf4 2720  1055adelevin  2002-10-14 11:21
p130   bt1sqtf4 1753  520 aginer2002-10-14 10:33
p143   bt1sqtf4 1658  518 alchippe  2002-10-14 10:30
p144   bt1sqtf4 1777  663 amaragou  2002-10-14 10:33
p175   bt1sqtf4 2976  1148ascatola  2002-10-14 11:30
p176   bt1sqtf4 3039  1164bceillie  2002-10-14 11:36
p135   bt1sqtf4 1224  503 blegrand  2002-10-14 10:07
p122   bt1sqtf4 4692  616 CAPTMA1   2002-10-14 09:53
p163   bt1sqtf4 2577  813 cfrancoi  2002-10-14 11:14
p154   bt1sqtf4 2200  914 chtuffre  2002-10-14 10:54
p146   bt1sqtf4 1848  589 cky   2002-10-14 10:35
p116   bt1sqtf4 4476  581 cvanlath  2002-10-14 09:42
..

How can i extract the 5 parameter ie the PID and put all in a an array?
Thanks for your precious help.

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: Regexp with 0

2002-09-18 Thread $Bill Luebkert

Muñoz O, Normann (Valparaíso) wrote:
> Hi, I have a question:
> 
> I get from STNDIN a string, for each caracter I check if it belong to a 
> predifined  group, the problem is that the caracter '0' is in that 
> group'. As 0 es false, the match doesn't consider it.
> 
> ¿How can I do that so the match take it as a caracter an not as false?
> 
> CARACTER[$i] =~/^(a|b|1|0)/g;

If I understand your Q:

use strict;

my @char = split //, 'ab1cdef0';

for (my $ii = 0; $ii < @char; $ii++) {
if ($char[$ii] =~ /^(a|b|1|0)/) {
print "$char[$ii] OK\n";
}
}

__END__



-- 
   ,-/-  __  _  _ $Bill Luebkert   ICQ=162126130
  (_/   /  )// //   DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //  http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_http://www.todbe.com/

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Regexp with 0

2002-09-18 Thread Norris, Joseph
Title: Regexp with 0



Normann,
 
Mi 
surgencia es que utiliza lo siguiente:
 
  
CARACTER[$i] 
=~/^([0|a|c|0])/
 
usando 
corchetes dira a Perl que este es una clase de caracter que pertenece al grupo 
que esta
buscando.
 
Espero que este le 
ayude.
 
Dispense que not tengo este teclado con acentos.  

 
Pregunta:  Donde esta su negocia - cual 
pais?
 
 
 


  -Original Message-From: "Muñoz O, Normann 
  (Valparaíso)" [mailto:[EMAIL PROTECTED]]Sent: Thursday, 
  September 05, 2002 9:44 AMTo: 
  [EMAIL PROTECTED]Subject: Regexp with 
  0
  Hi, I have a question: 
  I get from STNDIN a string, for each caracter I 
  check if it belong to a predifined  group, the problem is that the 
  caracter '0' is in that group'. As 0 es false, the match doesn't consider 
  it.
  ¿How can I do that so the match take it as a 
  caracter an not as false? 
  CARACTER[$i] =~/^(a|b|1|0)/g; 
  Thanks. 
  ATTE: 
  Normann Muñoz Oyarzún. Administrador de Sistemas El Mercurio de Valparaíso S.A.P. 264188 - 204189 [EMAIL PROTECTED] 


RE: Regexp with 0

2002-09-18 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Title: Regexp with 0



    Change to an if:
 
    
if ( CARACTER[$i] =~ /^(a|b|1|0)/g; 
) {
    #true
 }else {
    # false
 }
 
Wags ;)

  -Original Message-From: "Muñoz O, Normann   (Valparaíso)" [mailto:[EMAIL PROTECTED]]Sent: Friday,   September 06, 2002 14:36To: 
  [EMAIL PROTECTED]Subject: Regexp with   0
  Hi, I have a question: 
  I get from STNDIN a string, for each caracter I 
  check if it belong to a predifined  group, the problem is that the   caracter '0' is in that group'. As 0 es false, the match doesn't consider 
  it.
  ¿How can I do that so the match take it as a 
  caracter an not as false? 
  CARACTER[$i] =~/^(a|b|1|0)/g; 
  Thanks. 
  ATTE: 
  Normann Muñoz Oyarzún. Administrador de Sistemas El Mercurio de Valparaíso S.A.P. 264188 - 204189 [EMAIL PROTECTED] 

**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.





Re: regexp

2002-08-14 Thread Carl Jolley

On Wed, 14 Aug 2002, Jacobson, Karl wrote:

> I am trying simply to do a search and replace and have identified the string
> that I want to replace with another.
>
> $_ holds the string to be manipulated
> $was holds the search string (split from an input file)
> $is holds the replacement string (also split from an input file)
>
> s/$was/$is/; doesn't work and I expected that it would.  What is missing?
>

>From the information you provided, nothing appears wrong.

Additional useful information:

1. When you split the $was and $is variables from an input line,
   did you chomp() the line first to make sure that the variables
   didn't end up containing a trailing \n character. What about
   trailing spaces?

2. Does $was or $is contain any regex metacharacter or / character?
   If yes (or maybe) you need to change your regex to:

  s/\Q$was\E/\Q$is\E/;

For debugging purposes, I suggest that you do:

print SDTERR "previous value: $_\n";
print STDERR "length(\$was) = ",length($was),"\n";
print STDERR "\$was: $was\n";
print STDERR "length(\$is) = ",length($is),"\n";
print STDERR "\$is: $is\n";
if (s/$was/$is/) {
if ($was eq $is) {
   print STDERR "\$was eq \$is\n";
}
else {
  print STDERR "new value: $_\n";
   }
}
else {
  print STDERR "target $was was not found in $_\n";
}

Does the output produced show you where the problem is?

 [EMAIL PROTECTED] 
 All opinions are my own and not necessarily those of my employer 

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: regexp

2002-08-14 Thread Jing Wee

At 03:45 PM 8/14/2002 -0700, you wrote:
>I am trying simply to do a search and replace and have identified the string
>that I want to replace with another.
>
>$_ holds the string to be manipulated
>$was holds the search string (split from an input file)
>$is holds the replacement string (also split from an input file)
>
>s/$was/$is/; doesn't work and I expected that it would.  What is missing?
>
>Karl

I think the $was string may be a different case from the $_ string.  Try 
ignore case:

s/$was/$is/i;

If you needs multiple replacement:

s/$was/$is/ig;

Jing Wee



>___
>Perl-Win32-Users mailing list
>[EMAIL PROTECTED]
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: regexp

2002-08-14 Thread Carter Thompson



Interesting, seems to work fine.  Verify the 
contents of $was and $is and then try this:

($newstring = $_) =~ s/$was/$is/;

print ("Newstring is: $newstring\n");

Cheers,

Carter.



> -Original Message-
> From: Jacobson, Karl [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 14, 2002 3:46 PM
> To: [EMAIL PROTECTED]
> Subject: regexp
> 
> 
> I am trying simply to do a search and replace and have 
> identified the string
> that I want to replace with another.
> 
> $_ holds the string to be manipulated
> $was holds the search string (split from an input file)
> $is holds the replacement string (also split from an input file)
> 
> s/$was/$is/; doesn't work and I expected that it would.  What 
> is missing?
> 
> Karl
> 
> 
> ___
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Regexp needed

2002-07-24 Thread Mike Kalinovich

Hello all,

I'm at a bit of a loss as to why the same script on two servers are
experiencing a difference in opinion.

Both are NT4 with all the latest and greatest patches from MS.
Both are running SP6a
Both are running ActiveState v5.2.2

The CGI script is from tools4webmasters.com
This is an excerpt:

foreach $key (keys (%ENV)) {
if ($key eq 'DOCUMENT_ROOT') {
print "$key$space=$ENV{$key}Your
base directory (the \"/home/yourname\" part)\n";
}
else {
print "$key$space=$ENV{$key}\n";
}
}

The script goes through all the Environment keys and reports them back.
Except for the key of:
 Perl5.00503 =

On one server it is blank, on the other it reports
 perl: C:\Perl\bin\perl.EXE

I am at a loss as to where this is coming from.  If someone could share this
information with me.  The system environment variables do not contain this
on either server.

Any help would be much appreciated,
Mike Kalinovich

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Regexp needed

2002-03-05 Thread Thomas Bätzler

Lee Goddard [[EMAIL PROTECTED]] suggested:
> 1. Read the regex POD (perldoc perlre) or better
> buy the Programming Perl book and read its great regex pages.

An of course ORA also has the wonderful "Mastering
Regular Expressions" by Jeffrey Friedl (aka the Owl
book), which gives you a nice grounding and comparative
analysis of various RE engines aswell.

MfG,
-- 
Thomas Bätzler, Network Engineer, Network Operations EMEA
Peregrine Systems GmbH web: www.peregrine.com
Steinhäuserstraße 22 phone: +49-721-98143-166
D-76135 Karlsruhe / Germanyfax: +49-721-98143-196
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: Regexp needed

2002-03-05 Thread $Bill Luebkert

Jorge Goncalvez wrote:

> hi, i have this:
> my ($Path) = $MountsPath =~ /(.+?)cygwin/;
> but I wanted to get rid of the "/".
> because $MountsPath could be c:/cygwin or c:/xyz/cygwin or c:/xyz/zyx/cygwin and 
> i wanted $Path = c: or c:/xyz or c:/xyz/zyx .
> And now $Path= c:/ or c:/xyz or c:/xyz/zyx.
> How can I do ?


Just add it to the RE:

my ($Path) = $MountsPath =~ /(.+?)\/cygwin/;
or checking for / or \:
my ($Path) = $MountsPath =~ /(.+?)[\/\\]cygwin/;

or do a chop if you are sure it's there:

chop $Path;

-- 
   ,-/-  __  _  _ $Bill Luebkert   ICQ=14439852
  (_/   /  )// //   DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //  http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_http://www.todbe.com/

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: regexp matching more unpredictable in ActivePerl?

2001-04-04 Thread Ian . Stewart




Looks like 5.6 is returning different results, regardless of platform.

What happens if you replace '\w+\W+' with \b (word boundary) ?


Regards,
Ian




To: 



       [EMAIL PROTECTED]

cc:         (bcc: Ian Stewart/Great Lakes/AirTouch)

bcc:        Ian Stewart/Great Lakes/AirTouch



Subject:        Re: regexp matching more unpredictable in ActivePerl?







[IMAGE]

> No one has yet (at least as far as I've noticed) posted results using Perl

5.6 on UNIX.



I did in my second post. This isn't my second post but a smaller example:



---

use strict;

foreach (10, 20, 30, 40, 50) {



        my $string = 'word ' x $_;



        if ( $string =~ /((?:\w+\W+){0,25})$/ ) {

               print "words: $_ length: ", length($1), "\n";

       }



}

---



This is perl, version 5.005_03 built for MSWin32-x86-object

C:\temp>perl foo.pl

words: 10 length: 50

words: 20 length: 100

words: 30 length: 125

words: 40 length: 125

words: 50 length: 125



This is perl, v5.6.0 built for i386-openbsd

$ perl foo.pl

words: 10 length: 50

words: 20 length: 100

words: 30 length: 19

words: 40 length: 69

words: 50 length: 114









(Embedded image moved to file: pic22206.pcx)


 pic22206.pcx


Re: regexp matching more unpredictable in ActivePerl?

2001-04-04 Thread Ian . Stewart




But we are getting the same results. 


 Results have been posted for Perl 5.00x on
UNIX, Perl 5.00x on Win32 (AKA Build 522) and Perl 5.6 on Win32.

The results for Perl 5.00x on UNIX and Perl 5.00x on Win32 match.  No one has
yet (at least as far as I've noticed) posted results using Perl 5.6 on UNIX.


Regards,
Ian




To:        [EMAIL PROTECTED]
cc:        [EMAIL PROTECTED] (bcc: Ian Stewart/Great
Lakes/AirTouch)
bcc:        Ian Stewart/Great Lakes/AirTouch

Subject:        Re: regexp matching more unpredictable in ActivePerl?



[IMAGE]
> I am no regex expert,  but maybe it has to do with the underlying regex
> engine (i.e. NFA, DFA etc) and the implicit/explicit greediness of that
> engine for the specific boxes used.

Regardless of the implimentation of the engine, we should at least be
getting the same results across different platforms. I'm sure the RE
could be optimized tremendiously...
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



(Embedded image moved to file: pic01182.pcx)

 pic01182.pcx


Re: regexp matching more unpredictable in ActivePerl?

2001-04-04 Thread Ron Grabowski

> I am no regex expert,  but maybe it has to do with the underlying regex
> engine (i.e. NFA, DFA etc) and the implicit/explicit greediness of that
> engine for the specific boxes used.

Regardless of the implimentation of the engine, we should at least be
getting the same results across different platforms. I'm sure the RE
could be optimized tremendiously...
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



RE: regexp matching more unpredictable in ActivePerl?

2001-04-04 Thread Joseph P. Discenza

[EMAIL PROTECTED]
: Also, if you start the regex at the beginning  /^\W((\w+\W+){0,25})/)
: there is no output

Perhaps because there is no non-word character at the beginning
of "word word word ..." :)

Joe

==
  Joseph P. Discenza, Sr. Programmer/Analyst
   mailto:[EMAIL PROTECTED]
 
  Carleton Inc.   http://www.carletoninc.com
  219.243.6040 ext. 300fax: 219.243.6060
 
Providing Financial Solutions and Compliance for over 30 Years

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



Re: RegExp Question

2001-02-05 Thread Philip Newton

John Giordano wrote:
> $grep_deferred = system ('findstr DeferredStatus response1');
> 
> print "$grep_deferred\n\n";
[snip]
> $grep_deferred has this in it:
> 
>  src="/images/btnstats.gif" width=120 height=40 border=0 alt="Mail
> Status">

Are you sure? Try printing out "bloop\nblip\n$grep_deferred\nblep\n" and see
whether this  line comes between "blip" and "blep".

>From `perldoc -f system`:

 The return value is the exit status of the program as returned
 by the `wait' call. To get the actual exit value divide by 256.

So if $grep_deferred is the return value from system, it's probably a
number. The line you're seeing on the screen is presumably the output of
findstr, which went to STDOUT; since you didn't redirect STDOUT, it went the
same place your print went.

You probably want `` (backticks).

ObTMTOWTDI: if you're looking for a fixed substring such as ' sub { $a = index '', ' sub { $a = index '[a
href="/c9410ee04de9845704db8951dfde015b/DeferredStatus">', ' sub { $a = '' =~ / sub { $a = '[a
href="/c9410ee04de9845704db8951dfde015b/DeferredStatus">' =~ / sub { $a = index 'fhuhge8a goija fgoja w04gua
roigj oöijf g9a8u onigö lfsdkj gölija osij ga0 jügojar öoigj öosijd ü08g9u
gaji fäöigjah+w r0g9j aäüjäfpoiajs öoijfd +ajsd fäüpioaj öwoeijf öoasuidhf
p9iawh üefhaj woeijg awopihg apiuehrg üaiowj eoöfigjaw ejif', ' sub { $a = index 'fhuhge8a goija fgoja w04gua
roigj oöijf g9a8u onigö lfsdkj gölija osij ga0 jügojar öoigj öosijd ü08g9u
gaji fäöigjah+w r0g9j aäüjäfpoiajs öoijfd +ajsd fäüpioaj öwoeijf öoasuidhf
p9iawh üefhaj woeijg awopihg apiuehrg üaiowj eoöfigjaw ejif[a
href="/c9410ee04de9845704db8951dfde015b/DeferredStatus">', ' sub { $a = 'fhuhge8a goija fgoja w04gua roigj
oöijf g9a8u onigö lfsdkj gölija osij ga0 jügojar öoigj öosijd ü08g9u gaji
fäöigjah+w r0g9j aäüjäfpoiajs öoijfd +ajsd fäüpioaj öwoeijf öoasuidhf p9iawh
üefhaj woeijg awopihg apiuehrg üaiowj eoöfigjaw ejif' =~ / sub { $a = 'fhuhge8a goija fgoja w04gua roigj
oöijf g9a8u onigö lfsdkj gölija osij ga0 jügojar öoigj öosijd ü08g9u gaji
fäöigjah+w r0g9j aäüjäfpoiajs öoijfd +ajsd fäüpioaj öwoeijf öoasuidhf p9iawh
üefhaj woeijg awopihg apiuehrg üaiowj eoöfigjaw ejif[a
href="/c9410ee04de9845704db8951dfde015b/DeferredStatus">' =~ / sub { $a = 1; },
});

__END__

Output:
Benchmark: timing 500 iterations of assign, index.end.found,
index.end.notfound, index.start.found, inde
x.start.notfound, regex.end.found, regex.end.notfound, regex.start.found,
regex.start.notfound...
assign:  0 wallclock secs ( 1.02 usr +  0.00 sys =  1.02 CPU) @
4897159.65/s (n=500)
index.end.found:  9 wallclock secs ( 9.79 usr +  0.00 sys =  9.79 CPU) @
510516.64/s (n=500)
index.end.notfound: 12 wallclock secs (12.38 usr +  0.00 sys = 12.38 CPU) @
404007.76/s (n=500)
index.start.found:  3 wallclock secs ( 2.49 usr +  0.00 sys =  2.49 CPU) @
2004811.55/s (n=500)
index.start.notfound:  5 wallclock secs ( 5.42 usr +  0.00 sys =  5.42 CPU)
@ 922849.76/s (n=500)
regex.end.found: 12 wallclock secs (11.42 usr +  0.00 sys = 11.42 CPU) @
437943.42/s (n=500)
regex.end.notfound: 13 wallclock secs (13.34 usr +  0.00 sys = 13.34 CPU) @
374840.69/s (n=500)
regex.start.found:  5 wallclock secs ( 3.91 usr +  0.00 sys =  3.91 CPU) @
1280081.93/s (n=500)
regex.start.notfound:  7 wallclock secs ( 6.38 usr +  0.00 sys =  6.38 CPU)
@ 783821.92/s (n=500)
  Rate regex.end.notfound index.end.notfound
regex.end.found index.end.found regex.start.notfound index.start.notfound
regex.start.found index.start.found assign
regex.end.notfound374841/s ---7%
-14%-27% -52% -59%  -71%
-81%   -92%
index.end.notfound404008/s 8% --
-8%-21% -48% -56%  -68%
-80%   -92%
regex.end.found   437943/s17% 8%
---14% -44% -53%  -66%
-78%   -91%
index.end.found   510517/s36%26%
17%  -- -35% -45%  -60%
-75%   -90%
regex.start.notfound  783822/s   109%94%
79% 54%   -- -15%  -39%
-61%   -84%
index.start.notfound  922850/s   146%   128%
111% 81%  18%   --  -28%
-54%   -81%
regex.start.found1280082/s   242%   217%
192%151%  63%  39%--
-36%   -74%
index.start.found2004812/s   435%   396%
358%293% 156% 117%   57%
--   -59%
assign   4897160/s  1206%  1112%
1018%859% 525% 431%  283%
144% --
___
Perl-Win32-

Re: RegExp Question

2001-02-04 Thread $Bill Luebkert

John Giordano wrote:
> 
> Hello,
> 
> Could someone please tell me why this:
> 
> ###
> $grep_deferred = system ('findstr DeferredStatus response1');
> 
> print "$grep_deferred\n\n";
> 
> if ($grep_deferred =~ / 
> print "It contains  } else {
> 
> print "It doesn't contain  }
> -
> doesn't find this:
> 
>  
> The above code may need some further explanation.  I am trying to extract
> the  
> $grep_deferred has this in it:
> 
>  src="/images/btnstats.gif" width=120 height=40 border=0 alt="Mail
> Status">
> 
> < doesn't need a backslash in front of it right?

Correct, it doesn't.  This test snippet works fine for me (I modified 
your RE, but it works your way too):

use strict;

my $grep_deferred = 
  q{} . 
  q{};


print "$grep_deferred\n\n";

if ($grep_deferred =~ /http://www.todbe.com/
  / ) /--<  o // //  Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_http://www.freeyellow.com/members/dbecoll/
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



Re: Regexp?

2001-01-23 Thread Philip Newton

Cornish, Merrill wrote:
> In list context, m//g returns a list of all matches.  You 
> could count the elements in the list.  

For example, like this:

$count = () = $string =~ /foo/g;

The assignment to () (empty list) puts the match in list context, and the
scalar assignment then counts how many elements were available to be
assigned to the list. Or something like that. It works, at any rate.

Cheers,
Philip
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



RE: Regexp?

2001-01-19 Thread Ted W.

Does not the m// when used like:

count = m//ig;

?
TW



On Fri, 19 Jan 2001, Cornish, Merrill wrote:

> s/// will return the number of replacements it makes.  If you replace the
> substring with itself, then you will get the count without _appearing_ to
> make any replacements.
>
> Merrill
>
> > -Original Message-
> > From:   Roman Melihhov [SMTP:[EMAIL PROTECTED]]
> > Sent:   Friday, January 19, 2001 2:22 PM
> > To: '[EMAIL PROTECTED]'
> > Subject:Regexp?
> > Importance: High
> >
> > Hi,
> > Is there an elegant way to determine number of times substring is repeated
> >
> > within a string except a loop with incrementing counter. Regexp perhaps?
> > Ideas appreciated.
> >
> > Roman.
> >
> >
> ___
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
>

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



Re: Regexp?

2001-01-19 Thread Michael D. Schleif


Roman Melihhov wrote:
> 
> Is there an elegant way to determine number of times substring is repeated
> within a string except a loop with incrementing counter. Regexp perhaps?
> Ideas appreciated.

#! perl -w
use strict;
my $str = "iamike mike is a good guy but,mikeisn'talwaysas
cleverasmikecanbe";
my $match = "mike";
my $count = $str =~ s!$match!$&!g;
print "String -> $str\n";
print "Match -> $match\n";
print "Count -> $count\n";
exit 0;

Hope this helps . . .

-- 

Best Regards,

mds
mds resource
888.250.3987

"Dare to fix things before they break . . . "

"Our capacity for understanding is inversely proportional to how much we
think we know.  The more I know, the more I know I don't know . . . "
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



RE: Regexp?

2001-01-19 Thread Cornish, Merrill

s/// will return the number of replacements it makes.  If you replace the
substring with itself, then you will get the count without _appearing_ to
make any replacements.

Merrill

> -Original Message-
> From: Roman Melihhov [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, January 19, 2001 2:22 PM
> To:   '[EMAIL PROTECTED]'
> Subject:  Regexp?
> Importance:   High
> 
> Hi,
> Is there an elegant way to determine number of times substring is repeated
> 
> within a string except a loop with incrementing counter. Regexp perhaps? 
> Ideas appreciated.
> 
> Roman.
> 
> 
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



RE: Regexp questions...

2000-11-19 Thread Carl Jolley

On Sat, 18 Nov 2000, Naftel, Bill S wrote:

> Carl, i think i see where you're going by capturing the pieces in $1,
> $2, correct? then you just have to check each to be < 255? is there
> some, pardon, 'slick' way to do this say all at once?

The only 'slick' (perhaps some would say sick) way I can think of would
seem to be a little contrived.  You could use the 'e' flag to call a
subroutine which would reset a flag if the any of the values exceed 255.
For example like this: 

$ok=1;
$ok &= $dotted_quad =~ s/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/&v/e;
sub v {return ($ok=$1<256&&$2<256&&$3<256&&$4<256)? $&: ''}

In addition to being a little too "cute" this code would degrade the
effencicy of all the rest of the regex expressions in the program by
use of the $& variable. It also would destroy the $dotted_quad variable
if there any of the group's value exceeded 255. That could be avoided
by a minor rewrite of the code. On balance, a separate following statement
or at least an && expression to check the values of the groups would be
more effecient and clear. 

 [EMAIL PROTECTED] 
 All opinions are my own and not necessarily those of my employer 

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users