Not knowing which post to reply to...
So now that we've determined that "$ x" behaves differently from "@ x", why stop there?
DB<1> $x = 'DollarX'
DB<2> @x = 'a'..'g'
DB<3> %x = qw(1 a 2 b 3 c)
DB<4> sub x { print "This is Sub x\n" }
DB<5> p "<$x> <@x> <%x> <&x>"
<DollarX> <a b c d e f g> <%x> <&x>
DB<6> p "<$ x> <@ x> <% x> <& x>"
<DollarX> <@ x> <% x> <& x>
DB<7> p "$ #x"
Final $ should be \$ or $name at (eval 12)[C:/Perl/lib/perl5db.pl:17]
+line 2, within string
syntax error at (eval 12)[C:/Perl/lib/perl5db.pl:17] line 2, near "}
+"$ #x""
So "$ x" is the only one this works for, and it breaks for "$ #x", even though that looks like a scalar (and it probably shouldn't break!). But "$ x[0]" produces "a", and so does "$ x{1}".
I'm sure there's some Good Reason Why This Is So...Perhaps it's easy to figure out what to do with "$x", but there are more options with "@x". The string interpolation aspect of ignoring whitespace was probably not updated when "@x" interpolation was added. [I secretly hoped Merlyn would have the skinny on that -- but I'm sure he would have said so.]
-QM
--
Quantum Mechanics: The dreams stuff is made of
-
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.
|