I have attempted to explain my question with 2 examples using 'some\text' and "some\text" both of which get stored as I understood they should. However, 'some\\text' and "some\\text" don't behave as you would expect and are NOT stored with the same rules as the first case because in the first case, the compiler sees the single quotes and stores the characters correctly by pushing an additional '\' to the PV array as it should. What is going wrong, however, is the case when it sees a second '\' in the literal case, and doesn't push another '\' onto the PV.
use Devel::Peek;
# literal case - PV's are the same
$txt = 'some\text';
print "Case 1 'some\\text': $txt\n-------\n";
# PV gets an extra '\' pushed on it.
Dump($txt);
$txt = 'some\\text';
print "\nCase 2 'some\\\\text: $txt\n-------\n";
#PV does NOT get an extra '\' pushed on to it
Dump($txt);
# quoted case - PV's handle '\' as expected
$txt = "some\text";
print "\nCase 3 \"some\\text\": $txt\n-------\n";
Dump($txt);
#
$txt = "some\\text";
print "\nCase 4 \"some\\\\text\": $txt\n-------\n";
Dump($txt);
If you actually try these examples, then you can see for yourself how the scalars are getting stored.
Nuff said. I will ask the perl porters from here.
-
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.
|