Hello, Perl Monks!

I have been having problems with string searches. I learned from a Perl Monks user that /m or /s were to be replacements for the deprecated "$*" which I am encountering in some old code that I didn't write, but need to modify to a newer system (using perl 5.14.2).

The script I am editing has the statement "$* = 0;". $* is never used again in the script. I read elsewhere that if I commented that statement out in the perl versions where it was deprecated, nothing would happen. I don't feel sure about that.

The docs were not very satisfying, so I decided to play around with various situations regarding pattern matching using /m, /s or just plain / to see what happens. Here is a script I wrote:

#! /usr/bin/perl -w $re=qr/foo$/; print $re; print "\n"; print "foo\\nbar\\n =~ \/$re\/s \t"; print "foo\nbar\n" =~ /$re/s ?"true":"false"; print "\n"; print "foo\\nbar\\n =~ \/$re\/m \t"; print "foo\nbar\n" =~ /$re/m ?"true":"false"; print "\n"; # print "fred\\nfoo\\nbar\\n =~ \/$re\/s \t"; print "fred\nfoo\nbar\n" =~ /$re/s ?"true":"false"; print "\n"; print "fred\\nfoo\\nbar\\n =~ \/$re\/m \t"; print "fred\nfoo\nbar\n" =~ /$re/m ?"true":"false"; print "\n"; # print "foo =~ \/$re\/s \t"; print "foo" =~ /$re/s ?"true":"false"; print "\n"; print "foo =~ \/$re\/m \t"; print "foo" =~ /$re/m ?"true":"false"; print "\n"; print "\\nfoo =~ \/$re\/s \t"; print "\nfoo" =~ /$re/s ?"true":"false"; print "\n"; print "\\nfoo =~ \/$re\/m \t"; print "\nfoo" =~ /$re/m ?"true":"false"; print "\n"; print "foobar =~ \/$re\/s \t"; print "foobar" =~ /$re/s ?"true":"false"; print "\n"; print "foobar =~ \/$re\/m \t"; print "foobar" =~ /$re/m ?"true":"false"; print "\n"; print "bar\\nfoo\\n =~ \/$re\/s \t"; print "bar\nfoo\n" =~ /$re/s ?"true":"false"; print "\n"; print "bar\\nfoo =~ \/$re\/m \t"; print "bar\nfoo" =~ /$re/m ?"true":"false"; print "\n"; print "bar\\nfoo\\n =~ \/$re\/ \t"; print "bar\nfoo\n" =~ /$re/ ?"true":"false"; print "\n"; print "foo\\nbar\\n =~ \/$re\/ \t"; print "foo\nbar\n" =~ /$re/ ?"true":"false"; print "\n"; print "fred\\nfoo\\nbar\\n =~ \/$re\/ \t"; print "fred\nfoo\nbar\n" =~ /$re/ ?"true":"false"; print "\n"; print "fred\\nfoo\\nbar\\n =~ \/$re\/ \t"; print "fred\nfoo\nbar\n" =~ /$re/ ?"true":"false"; print "\n"; print "foo =~ \/$re\/ \t"; print "foo" =~ /$re/ ?"true":"false"; print "\n"; print "foobar =~ \/$re\/ \t"; print "foobar" =~ /$re/ ?"true":"false"; print "\n"; print "\\nfoo =~ \/$re\/ \t"; print "\nfoo" =~ /$re/ ?"true":"false"; print "\n";
The output was:
(?^:foo$) foo\nbar\n =~ /(?^:foo$)/s false foo\nbar\n =~ /(?^:foo$)/m false fred\nfoo\nbar\n =~ /(?^:foo$)/s false fred\nfoo\nbar\n =~ /(?^:foo$)/m false foo =~ /(?^:foo$)/s true foo =~ /(?^:foo$)/m true \nfoo =~ /(?^:foo$)/s true \nfoo =~ /(?^:foo$)/m true foobar =~ /(?^:foo$)/s false foobar =~ /(?^:foo$)/m false bar\nfoo\n =~ /(?^:foo$)/s true bar\nfoo =~ /(?^:foo$)/m true bar\nfoo\n =~ /(?^:foo$)/ true foo\nbar\n =~ /(?^:foo$)/ false fred\nfoo\nbar\n =~ /(?^:foo$)/ false fred\nfoo\nbar\n =~ /(?^:foo$)/ false foo =~ /(?^:foo$)/ true foobar =~ /(?^:foo$)/ false \nfoo =~ /(?^:foo$)/ true
I even went so far as to tabulate the results (by inspection). A "/" means "\n":
/m /s none foo/bar/ F F F fred/foo/bar F F F foo T T T /foo T T T foobar F F F bar/foo/ T T T bar/foo T T T

In none of these situations did /m or /s produce a different result from each other. And in all cases, just having / with nothing after it produced the same results as the other two with options after them. I am not clear at all about the purpose of /m and /s (or the original purpose of $*, for that matter).

If anyone can clear this up, or can suggest situations I didn't test, I would be grateful.

sciguy


In reply to /s and /m don't seem to be doing anything by sciguy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.