Awesome Corion, great answer! And you've pinned the tail on the donkey--I was overconfident in my knowledge and thought I knew what I was doing when I didn't :-)

However, now I'm wondering why it ever works at all! In my test I did this:

#!/usr/bin/perl use Data::Dumper; my $arg = shift; my %actualhash = eval $arg; print Dumper \%actualhash; #old bad way my %badhash = ('r,2,g,2,w,1'); #if you don't think too hard, this look +s correct. print "\n%badhash:\n"; print Dumper \%badhash; print $@; my %hash = ('r',2,'g',2,'w',1); print "\n%hash:\n"; print Dumper \%hash; #print $@; unclutter output for posting to perlmonks--it just repeats +the first error, of course my @array = qw/r 2 g 2 w 1/; my %newhash = @array; print "\npassing through qw:\n"; print Dumper \%newhash; #print $@;
Which yields:
rasto@frodo:~/cheat$ ./test.pl 'r,2,g,2,w,1,q,1' $VAR1 = {}; %badhash: $VAR1 = { 'r,2,g,2,w,1' => undef }; Can't find string terminator "," anywhere before EOF at (eval 1) line +1. %hash: $VAR1 = { 'w' => 1, 'r' => 2, 'g' => 2 }; passing through qw: $VAR1 = { 'w' => '1', 'r' => '2', 'g' => '2' };
So indeed, when I saw:
$VAR1 = { 'r,2,g,2,w,1' => undef };
It became obvious that I had a syntax error and I quickly saw the problem--fuzzy thinking on my part :-)

But what's weird then is why it works at all, and why it stops working when adding a 'q'. I'm really quite curious now, although for my practical purposes it is only an intellectual excersize.

I'm thinking for convenience I'll just pass it through 'qw' as I did in the test above, which will actually make it more convenient to type my arguments, lol! ;-)

Thanks again for the excellent answer that taught me a problem solving skill, as opposed to simply answering :-D


In reply to Re^2: eval doesn't like the letter 'q'? by rastoboy
in thread eval doesn't like the letter 'q'? by rastoboy

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.