Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

It's a bit subtler than that.

When you write string literals, single-quoting them make them contain exactly the characters you typed, while double-quoting them activates the interpolation mechanism.

On the other hand, when you use a string as a regular expression, it gets interpreted by the regex engine.

For example:

$literal='abc@array$'; @array=(1,2,3); $interpolated="abc@array\$"; print 'literal: ',$literal,"\n"; print 'interp.: ',$interpolated,"\n"; if ($literal =~ /$literal/) { print "literal matches itself\n" } else { print "literal doesn't match itself\n" } $literal2='abc@array'; if ($literal2 =~ /$literal2/) { print "literal2 matches itself\n" } else { print "literal2 doesn't match itself\n" } if ($literal2 =~ /$literal/) { print "literal2 matches literal\n" } else { print "literal2 doesn't match literal\n" }

This prints:

literal: abc@array$ interp.: abc1 2 3$ literal doesn't match itself literal2 matches itself literal2 matches literal

The first two lines are hopefully obvious. As for the others:

  • $literal does not match itself because, seen as a regexp, it requires the string it matches to end with a y (the $ is interpreted by the regexp engine)
  • $literal2 does match itself. This is to confirm that the regexp is not "double-quote-interpolated-expanded-whathaveyou": the @ is still a single character.
  • $literal2 matches $literal because it does end in a y.
OK, for the pedants: the string between the // is interpolated, but its contents are not further expanded. I felt that this was more noise than signal, in this case.
-- 
        dakkar - Mobilis in mobile

Most of my code is tested...

Perl is strongly typed, it just has very few types (Dan)


In reply to Re^3: substituted text is being interpreted by dakkar
in thread substituted text is being interpreted by j.goor

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-28 23:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found