To avoid further confusion, I suggest we take a step back and agree on how to communicate the strings appropriately. I think what is causing confusion here is that you are using single quotes to show strings*, and we, being Perl programmers, are assuming that Perl's rules for single-quoted string literals apply, but based on what you've written I don't think that's the definition you're using. So:
- When you write 'foo \x \\ \' \ bar', due to Perl's rules for single-quoted strings (Quote Like Operators: "A backslash represents a backslash unless followed by the delimiter or another backslash, in which case the delimiter or backslash is interpolated."), this string is actually the 16-character string «foo \x \ ' \ bar», as you can see when you execute the Perl code print 'foo \x \\ \' \ bar', "\n";.
- Note: I'm using these special quoting characters here to make it clear that I don't mean Perl's quotes. In PerlMonks' HTML, what I've written is «<c>my string here</c>». This is not an established standard, just something I'm doing in this node to differentiate between "", '', and "the characters the string literals actually represent".
- When you write "foo \x22 \\ \' \" bar", due to Perl's rules (same link as above), this string is actually the 15-character string «foo " \ ' " bar» (try print "foo \x22 \\ \' \" bar", "\n";). This is the format that tools like Data::Dump and Data::Dumper (with $Data::Dumper::Useqq=1; turned on, which I always recommend) will output. Because of this, I suggested you use this format to show us what strings you're working with.
- When you want to show us a string without any quoting/escaping/interpolation, then don't use '''s or ""'s. Just show us the string in PerlMonks' <code> tags, as in: My input is the 14-character string <code>my string here</code>., optionally add some special quotes like I showed above, and tell us the actual length of the string so we can verify.
- * Update: Another option is heredocs, as tybalt89 showed here; just make sure to put the heredoc marker into single quotes, as in my $str = <<'END'; ... END, to disable interpolation inside the heredoc. This might be useful because from your reply here, I seem to understand the single quotes are actually part of the string, which would also help explain the confusion we've been having. (Note the other quoting methods still work too, as in '\'...\'' and "'...'".)
- When you want to show us a regex, show us the Perl code and use a qr// operator, don't use quotes (and don't use qr'' either). Again, this is the least ambiguous format. (See also Regexp Quote Like Operators.)
- If you wanted to be really, really thorough, or there is some real confusion as to what your inputs are, then you could also show us the output of Devel::Peek's Dump(), or, for files, show us a hex dump of the file: On Linux, either hexdump -C filename or od -tx1c filename (see also).
I think once we've got that cleared up and we understand what your actual strings are, we'll be able to help much more effectively :-)
-
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.
|
|