CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Pattern matching

 



jbs
Deleted

Jul 30, 2000, 10:34 PM

Post #1 of 8 (3837 views)
Pattern matching Can't Post

#THIS PROGRAM IS TO FIX THE MATCHING ATTR PROBLEMS

@arr= qw(status new protocol file:// root D:/Waferweb/perlpract/Mirror/Mnz/Test/Chimp/Production/Parametric/op6500/IrChart/All/ByWafer/ForProduct/Jose1/ name MRS2_RES.gif chartts Fri_May_26_03:12:16_2000 attrib0 Mnz attrib1 Test attrib2 Chimp attrib3 Production attrib4 Parametric attrib5 op6500 attrib6 IrChart attrib7 All attrib8 ByWafer attrib9 ForProduct attrib10 Jose1);
$arrstr=join(' ',@arr);
$attr=('attrib0 Mnz attrib1 Test attrib2 Chimp attrib3 Production attrib4 Parametric attrib5 op6500 attrib6 IrChart attrib7 All attrib8 ByWafer attrib9 ForProduct attrib10 Jose1');

print "\narrstr:$arrstr \n";
print " attr:******************************************************************************************************************************************************************************* ********************$attr \n";

if ($attr =~ /$arrstr/) {
print " I match! \n" ;



}

else {
print " I dont match \n";


} I can seem to get the match, and the substr is the same as the main str. I would appreciate any help. Thanks


dws
Deleted

Jul 31, 2000, 11:07 AM

Post #2 of 8 (3837 views)
Re: Pattern matching [In reply to] Can't Post

Hint: examine $attr closely prior to the regex. You're got a print there. Read the results.



jbs
Deleted

Jul 31, 2000, 12:21 PM

Post #3 of 8 (3837 views)
Re: Pattern matching [In reply to] Can't Post

I'm not quite sure what you mean?


dws
Deleted

Jul 31, 2000, 1:56 PM

Post #4 of 8 (3837 views)
Re: Pattern matching [In reply to] Can't Post

I'll rephrase. What does $attr hold at the time the regex executes?

Further hint, what will $attr hold after:

$attr = ('foo', 'bar', 'baz');

[Later: Ignore this. I misread the original code fragment. Gotta use a bigger font on my laptop..]


[This message has been edited by dws (edited 08-02-2000).]


jbs
Deleted

Jul 31, 2000, 3:19 PM

Post #5 of 8 (3837 views)
Re: Pattern matching [In reply to] Can't Post

$atr holds the entire string, just like $arrstr holds the main string. The string does have a match, why doesnt perl find it?
-jbs


Kanji
User / Moderator

Aug 1, 2000, 9:16 AM

Post #6 of 8 (3837 views)
Re: Pattern matching [In reply to] Can't Post

 <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>$atr holds the entire string,<HR></BLOCKQUOTE>

No, I'm afraid it doesn't.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$attr = ( 'attrib0 Mnz ... ' ); # $attr = 1
$attr = ( 'attrib0', 'Mnz ...' ); # $attr = 2
$attr = ( 'attrib0', 'Mnz', '...' ); # $attr = 3</pre><HR></BLOCKQUOTE>

Hint: you want $attr to be a string not a list/array.


japhy
Enthusiast / Moderator

Aug 1, 2000, 9:38 AM

Post #7 of 8 (3837 views)
Re: Pattern matching [In reply to] Can't Post

Sorry, kanji, but that's not true.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$a = ('foo');
$b = ('foo','bar');
$c = ('foo','bar','quux');
print "$a $ b $c\n"; # foo bar quux
</pre><HR></BLOCKQUOTE>

Lists don't exist in scalar context, and therefore, you can't get the SIZE of a list in scalar context.

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher



[This message has been edited by japhy (edited 08-01-2000).]


japhy
Enthusiast / Moderator

Aug 1, 2000, 9:42 AM

Post #8 of 8 (3837 views)
Re: Pattern matching [In reply to] Can't Post

The main problem is you're searching in the wrong string:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$big = "a b c d e f g h i j k l m n o";
$small = "d e f g";
if ($small =~ /$big/) {
# this IS NOT true
}
if ($big =~ /$small/) {
# this IS true
}
</pre><HR></BLOCKQUOTE>

There's no need to use regexes, though. Use the index() function:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


if (index($big,$small) != -1) {
print "small is in big\n";
}
</pre><HR></BLOCKQUOTE>

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives