Ask a Question related to PERL Beginners, Design and Development.
-
Steve Hemond #1
RE : Regular expressions
Actually, I have to test two conditions to get into a block,
If the strings found are either "one two" or "two three", go ahead.
if ($text =~ /one two/ or /two three/)
Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
[email]shemond@smurfit.com[/email]
> -----Original Message-----
> From: James Edward Gray II [mailto:james@grayproductions.net]
> Sent: Wednesday, December 17, 2003 11:05 AM
> To: Hemond, Steve
> Cc: [email]beginners@perl.org[/email]
> Subject: Re: Regular expressions
>
>
> On Dec 17, 2003, at 9:59 AM, Hemond, Steve wrote:
>> found together.> > Hi again,
> >
> > I want to make a search on two words.
> >
> > If 'one two' is found, it is okay.
> > If 'one' is found, it is incorrect.
> > If 'two' is found, it is also incorrect.
> >
> > I want the search to return me occurences of 'one two'>> >
> > I am searching this way :
> > if ($text =~ /one two/)
> >
> > What I am doing wrong?
> Nothing that I can see. Although, /\bone two\b/ is probably
> slightly
> better. What's the problem?
>
> James
>Steve Hemond Guest
-
RE : RE : Regular expressions
I think I begin to understand... I begin by fetching the results of the ps -efA command and split it into many variables ($uid, $pid, etc.) ... -
[PHP] Q on Regular Expressions
* Thus wrote jsWalter (jsWalter@torres.ws): have you looked at strtotime()? http://php.net/strtotime The Date formats it can find are defined... -
[PHP-DEV] PHP regular expressions
Hello. In regex/utils.h there is a definition for DUPMAX: #ifdef _POSIX2_RE_DUP_MAX #define DUPMAX _POSIX2_RE_DUP_MAX #else #define DUPMAX 255... -
Help with regular expressions.
Apples and Oranges: I think your format string is wrong, try: {0:d} "Pablo Pecora" <pablo.pecora@itau.com.ar> wrote in message... -
help with regular expressions
Hello, just getting grips with Perl and RE, but need your help. I am trying to open a file, print its contents to a textbox, but extract... -
Jeff 'Japhy' Pinyan #2
Re: RE : Regular expressions
On Dec 17, Hemond, Steve said:
That code is the same as>Actually, I have to test two conditions to get into a block,
>
>If the strings found are either "one two" or "two three", go ahead.
>
>if ($text =~ /one two/ or /two three/)
if (($text =~ /one two/) or ($_ =~ /two three/)) { ... }
You want either
if ($text =~ /one two/ or $text =~ /two three/) { ... }
or
if ($text =~ /one two|two three/) { ... }
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest
-
James Edward Gray II #3
Re: RE : Regular expressions
On Dec 17, 2003, at 10:09 AM, Hemond, Steve wrote:
Now that is a mistake. ;)> Actually, I have to test two conditions to get into a block,
>
> If the strings found are either "one two" or "two three", go ahead.
>
> if ($text =~ /one two/ or /two three/)
if ($text =~ /\bone two\b/ || $text =~ /\btwo three\b/) {
James
James Edward Gray II Guest
-
Steve Hemond #4
RE : Regular expressions
Okay, here`s the real problem,
# ps -efA |grep dispatch
cspenard 33958 45716 0 09:08:05 pts/8 0:00 /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
msirois 37212 9842 0 08:41:17 pts/1 0:04 /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
My script passes each process and when it finds "dispatch genie" it holds its data in a hash table.
As you can see, dispatch genie is found in these two columns.
if ($cmd =~ /dispatch genie/) {
That returns absolutely nothing.
Why?
Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
[email]shemond@smurfit.com[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>> -----Original Message-----
> From: drieux [mailto:drieux@wetware.com]
> Sent: Wednesday, December 17, 2003 11:24 AM
> To: Perl Perl
> Subject: Re: Regular expressions
>
>
>
> On Dec 17, 2003, at 7:59 AM, Hemond, Steve wrote:
> [..]>> > I am searching this way :
> > if ($text =~ /one two/)
> >
> > What I am doing wrong?
> ok, I bite, what is the problem?
>
> given
> #!/usr/bin/perl -w
> use strict;
>
> while ( <DATA> ) {
> my $text = $_;
> if ($text =~ /one two/)
> {
> print "line is ok:\n\t$text";
> } else {
> print "WRONG!\n\t$text";
> }
> }
>
> __DATA__
> If 'one two' is found, it is okay.
> If 'one' is found, it is incorrect.
> If 'two' is found, it is also incorrect.
>
> we get
> line is ok:
> If 'one two' is found, it is okay.
> WRONG!
> If 'one' is found, it is incorrect.
> WRONG!
> If 'two' is found, it is also incorrect.
>
> What Problem?
>
>
> ciao
> drieux
>
> ---
>
>
> --
> To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
> For additional commands, e-mail: [email]beginners-help@perl.org[/email]
Steve Hemond Guest
-
James Edward Gray II #5
Re: RE : Regular expressions
On Dec 17, 2003, at 10:29 AM, Hemond, Steve wrote:
"returns nothing" is a little confusing. The test above should> Okay, here`s the real problem,
>
> # ps -efA |grep dispatch
> cspenard 33958 45716 0 09:08:05 pts/8 0:00
> /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
> msirois 37212 9842 0 08:41:17 pts/1 0:04
> /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
>
> My script passes each process and when it finds "dispatch genie" it
> holds its data in a hash table.
>
> As you can see, dispatch genie is found in these two columns.
>
> if ($cmd =~ /dispatch genie/) {
>
> That returns absolutely nothing.
>
> Why?
evaluate to true, if $cmd contains 'dispatch genie' and whatever is
inside the if block should be executed. If you're saying the if block
isn't being executed, well $cmd probably doesn't contain what you think
it does then.
James
James Edward Gray II Guest
-
Ed Christian #6
RE: RE : Regular expressions
Hemond, Steve wrote:
> Okay, here`s the real problem,
>
> # ps -efA |grep dispatch
> cspenard 33958 45716 0 09:08:05 pts/8 0:00
> /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
> msirois 37212 9842 0 08:41:17 pts/1 0:04
> /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
>
> My script passes each process and when it finds "dispatch genie" it
> holds its data in a hash table.
>
> As you can see, dispatch genie is found in these two columns.
>
> if ($cmd =~ /dispatch genie/) {
>
> That returns absolutely nothing.
>
> Why?
>
Again, that regexp works just fine. (If you're setting $cmd properly...)
Something else must be wrong that you're not sending in your email
requests. Send the actual code.
#!/usr/bin/perl -w
use warnings;
use strict;
while (<DATA>) {
chomp;
(/dispatch genie/) ? print "Hit\n" : print "Miss\n";
}
__DATA__
cspenard 33958 45716 0 09:08:05 pts/8 0:00
/prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
msirois 37212 9842 0 08:41:17 pts/1 0:04
/prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
Ed Christian Guest



Reply With Quote

