Electron One wrote, on Monday, March 10, 2003 13:12
: while(<>){
:     chomp;
:     if(/\s*\$[a-z]\w+\s*/i){
: #    if(/\b\$[a-z]\w+\b/i){
:         print "Matched: $` -- $& -- $' :\n";
:      }
:     else{
:        print "No match:$_\n";
:     }
: }
: 
: ############################testfile.txt##########################
: $he1lo is the name of a variable
: what is not allowed $0 is this
: but this is $a123wgfd343w cool
: this is correct though $hello dont know why didnt work before.
: I sure hope this doesnt pass alf$f12w32 cuz it shouldnt
: $alfonso does match though
: $hello
: ##################################################################
: 
: Now, if I run the program how it is, I get this,
: 
: Matched:  -- $he1lo  -- is the name of a variable :
: No match:what is not allowed $0 is this
: Matched: but this is --  $a123wgfd343w  -- cool :
: Matched: this is correct though --  $hello  -- dont know why didnt work 
: before. :
: Matched: I sure hope this doesnt pass alf -- $f12w32  -- cuz it shouldnt :
: Matched:  -- $alfonso  -- does match though :
: Matched:  -- $hello --  :
: No match:

: if i run it with the commented section as the if statement, and 
: the current 
: if statement commented out, i get this,
: 
: No match:$he1lo is the name of a variable
: No match:what is not allowed $0 is this
: No match:but this is $a123wgfd343w cool
: No match:this is correct though $hello dont know why didnt work before.
: Matched: I sure hope this doesnt pass alf -- $f12w32 --  cuz it shouldnt :
: No match:$alfonso does match though
: No match:$hello
: 
: Why doesn't the second match lines 1,3,4,5 and 6? In 
: the camel book(pg40), it says that the word bound \b matches the 
: beginning of lines.

The \b word boundary marks a boundary between a \w character and either
a \W character or one end of the line. I think what you really want is
this:

/(^|\W)\$[a-zA-Z]\w*\b/

Since $ is not a word character, you *do* get a word boundary when the $
appears in the middle of a word (hence your match on alf$f12w32 and nowhere
else). What you really want is to have the $ preceded by either the beginning
of the line or a non-word character. I also bet you *do* want to allow one-
character variables? If not, change the * back to a +.

Good luck,

Joe

==============================================================
          Joseph P. Discenza, Sr. Programmer/Analyst
               mailto:[EMAIL PROTECTED]
 
          Carleton Inc.   http://www.carletoninc.com
          574.243.6040 ext. 300    fax: 574.243.6060
 
Providing Financial Solutions and Compliance for over 30 Years
***** Please note that our Area Code has changed to 574! ***** 

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

Reply via email to