Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

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

>> So I test it out, like i do everything, and i do:  perl -e"%a=( 1..10, 11..20 );print keys %a" and I get no output.

Well, when I test in on my one and only Perl (5.6.1 build 628 on Win2k), I get this

H:\>perl -e"%a=( 1..10, 11..20 );print keys %a" 137159117319115
or in a more readable version
H:\>perl -e"%a=( 1..10, 11..20 );print qq{@{[keys %a]}}" 13 7 15 9 1 17 3 19 11 5
both of which look good to me.

crazyinsomniac continued

>> So now I says to me, this must be a bug, and to confirm, i try:

perl -MData::Dumper -e "%a= 1 .. 10, 2 .. 11 ;print Dumper \%a"
which yields nada, and then ...

Me again, when I test it, I get this - as expected.

H:\>perl -MData::Dumper -e "%a= 1 .. 10, 2 .. 11 ;print Dumper \%a" $VAR1 = { '7' => 8, '9' => 10, '1' => 2, '3' => 4, '5' => 6 };
Seems to work nicely. The % character that japhy mentioned is tucked inside the double quotes and is seen by Perl, not the cmd shell.

So where is the problem? Did I miss something here?

I am all for bashing the cmd shell (pun intended) when justified, but here I cannot confirm the problem.

Can you help me out on this, crazyinsomniac ?

Rudif

Update Could somemonk please set me straight on the operator precedence in the second example above?

I think that the assignment binds 1..10 to %a, whereas 2..11 has no effect other than being the return value from the comma operator, which is thrown away. Is this correct?


In reply to Re: perl -e hash assignment and range operator bug by Rudif
in thread perl -e hash assignment and range operator bug by crazyinsomniac

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.