Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using pattern matching on strings other than $_

Status
Not open for further replies.

Loon

Programmer
May 24, 2000
100
GB
Is it possible to use say commands such as:<br><FONT FACE=monospace><br>if (/<font color=red>regexp</font>/)<br>{<br>&nbsp;&nbsp;&nbsp;#does some stuff<br>}<br></font><br>But without having to use $_? currently I am able to re-assign the $_ variable with whatever string I want checked but this might cause problems if I ever require to pattern match with file contents...<br><br>I can't seem to find the relevant answers in any books!<br>Cheers<br>Loon<br>
 
easier than you think it is.......just explicitly use the previously implied match operator,&nbsp;&nbsp;'=~'.<br><FONT FACE=monospace><br>$string = 'this is a string of text and numbers 123456';<br>if ($str =~ /123/) <br>&nbsp;&nbsp;&nbsp;&nbsp;{ <br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;found 123 is string\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br></font><br><br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top