<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: perl - using a scaler variable to represent an R.E. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680182#M908221</link>
    <description>Change $pattern to &lt;BR /&gt;&lt;BR /&gt;$pattern=/humpty|jack/;&lt;BR /&gt;&lt;BR /&gt;get rid of the quotes&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
    <pubDate>Mon, 11 Mar 2002 13:32:42 GMT</pubDate>
    <dc:creator>harry d brown jr</dc:creator>
    <dc:date>2002-03-11T13:32:42Z</dc:date>
    <item>
      <title>perl - using a scaler variable to represent an R.E.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680181#M908220</link>
      <description>I am trying to write a perl script and I am confused.  I want to use a scalar variable to hold an RE against which to pattern match.  It doesnt work. eg&lt;BR /&gt;&lt;BR /&gt;$pattern='/humpty|jack/'&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;if ($variable_x =~ $pattern)&lt;BR /&gt;{&lt;BR /&gt;  print 'Match found for humpty or jack'&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Does not work.&lt;BR /&gt;&lt;BR /&gt;If instead of $pattern I use /$var_a|$var_b/ where $var_a = humpty and $var_b = jack then it works fine!  What am I not getting???</description>
      <pubDate>Mon, 11 Mar 2002 13:27:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680181#M908220</guid>
      <dc:creator>Mr Peter Kempner</dc:creator>
      <dc:date>2002-03-11T13:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: perl - using a scaler variable to represent an R.E.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680182#M908221</link>
      <description>Change $pattern to &lt;BR /&gt;&lt;BR /&gt;$pattern=/humpty|jack/;&lt;BR /&gt;&lt;BR /&gt;get rid of the quotes&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 11 Mar 2002 13:32:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680182#M908221</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-03-11T13:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: perl - using a scaler variable to represent an R.E.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680183#M908222</link>
      <description>The "/" is part of the syntax for the matching operation.&lt;BR /&gt;&lt;BR /&gt;Therefore do the following-&lt;BR /&gt;&lt;BR /&gt;$pattern='humpty|jack' &lt;BR /&gt;. &lt;BR /&gt;. &lt;BR /&gt;if ($variable_x =~ /$pattern/) &lt;BR /&gt;{ &lt;BR /&gt;print 'Match found for humpty or jack' &lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;Should work.&lt;BR /&gt;&lt;BR /&gt;Note- If $pattern does not change, you can use the "o" option (ie /$pattern/o) to have perl generate more effecient code for execution.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Mar 2002 14:23:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680183#M908222</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-03-11T14:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: perl - using a scaler variable to represent an R.E.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680184#M908223</link>
      <description>Rodney,&lt;BR /&gt;&lt;BR /&gt;I like your solution much better!&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 11 Mar 2002 14:35:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680184#M908223</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-03-11T14:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: perl - using a scaler variable to represent an R.E.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680185#M908224</link>
      <description>You got it almost right the first time, but you forgot to read the docs (use the qr// operator):&lt;BR /&gt;&lt;BR /&gt;$pattern = qr/humpty|jack/; &lt;BR /&gt;. &lt;BR /&gt;. &lt;BR /&gt;if ($variable_x =~ $pattern) &lt;BR /&gt;{ &lt;BR /&gt;   print 'Match found for humpty or jack' &lt;BR /&gt;   } &lt;BR /&gt;&lt;BR /&gt;Harry's solution is plain wrong: it'd asign the result of matching $_ against the pattern. Rodney's solution is technically correct, but still suboptimal and error-prone.</description>
      <pubDate>Mon, 11 Mar 2002 17:20:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680185#M908224</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-03-11T17:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: perl - using a scaler variable to represent an R.E.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680186#M908225</link>
      <description>Sorry, a wee "correction" to Rodney's answer.&lt;BR /&gt;&lt;BR /&gt;In deed you can use almost any character pair to embrace search and substituion patterns when using the operators m, s, y, tr&lt;BR /&gt;&lt;BR /&gt;At the shell type&lt;BR /&gt;&lt;BR /&gt;perldoc perlop&lt;BR /&gt;perldoc -f m&lt;BR /&gt;perldoc -f y&lt;BR /&gt;perldoc -f s&lt;BR /&gt;perldoc -f qr&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This comes handy when you have to deal with paths, as subdirectories are delimited by /, which you otherwise would have to escape by &lt;BR /&gt;instead of writing&lt;BR /&gt;&lt;BR /&gt;$path =~ /\/usr/\/local/\/bin/&lt;BR /&gt;&lt;BR /&gt;you can say&lt;BR /&gt;&lt;BR /&gt;$path =~ m|/usr/local/bin/|&lt;BR /&gt;&lt;BR /&gt;or &lt;BR /&gt;&lt;BR /&gt;$path =~ m(/usr/local/bin)&lt;BR /&gt;&lt;BR /&gt;Of course you can also reference variables in patterns&lt;BR /&gt;&lt;BR /&gt;@users = qw(Humpty Jack);&lt;BR /&gt;&lt;BR /&gt;print "found match\n" if ($name =~ /$users[0]|$users[1]/) &lt;BR /&gt;&lt;BR /&gt;You can even use the qr operator if you insist&lt;BR /&gt;&lt;BR /&gt;$pattern = qr(Humpty|Jack);&lt;BR /&gt;print "found match" if $name =~ $pattern;&lt;BR /&gt;&lt;BR /&gt;You can inverse logic by using '!~' instead of '=~'&lt;BR /&gt;But this should be familiar from awk.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Mar 2002 17:41:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-using-a-scaler-variable-to-represent-an-r-e/m-p/2680186#M908225</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2002-03-11T17:41:04Z</dc:date>
    </item>
  </channel>
</rss>

