cjkim has asked for the wisdom of the Perl Monks concerning the following question:

What does M"xxx" do? I tried print M"xxxx"; and perl does nothing.

Replies are listed 'Best First'.
Re: M"anything"
by japhy (Canon) on Aug 06, 2004 at 13:11 UTC
    This is why you should always code with strict and warnings. It saves you (and us) time. Please turn warnings on and try your code again.
    _____________________________________________________
    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: M"anything"
by herveus (Prior) on Aug 06, 2004 at 13:16 UTC
    Howdy!

    perl -Mstrict -Mwarnings -MO=Deparse -e 'print M"xxxx";' Name "main::M" used only once: possible typo at -e line 1. print M 'xxxx'; -e syntax OK

    ...or, in other words, the same thing that 'print STDOUT "xxxx"' does modulo the specific filehandle...what do *you* expect to happen when you print to the filehandle M? Is it open? Is it writable?

    yours,
    Michael
Re: M"anything"
by Limbic~Region (Chancellor) on Aug 06, 2004 at 13:27 UTC
    cjkim,
    There are two possibilities that I can think of:
    • M is a filehandle
    • M should have been a little m
    In the first case, print M "foo" would have printed "foo" to the file that M was opened to. It does not make any sense by itself (without the print), so it is very unlikely that this is what you mean.

    In the second case, it is used to change the delimiters of a regex. Typically used to get rid of the leaning toothpick problem.

    print "matched" if /\/foo\/bar\/index\.html/; # vs print "matched if m"foo/bar/index\.html";

    Cheers - L~R