Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

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

You appear to be very confused!

my $maxBits=60 is not a hash reference. 60 is a plain old scalar.

my %maxBits=60 is indeed wrong, because %maxBits is a hash, but 60 is again as plain old scalar. Perl will *try* to Do The Right Thing and assume that the right hand side is a list of key/value pairs, but it can't because there's an odd number of elements in the list (it gets treated as a list with one element). Hence the warning "Odd number of elements in hash assignment". It then, after warning you, extends the list by appending an undef, creating a hash that looks like this:

60 => undef

that is, the hash has a single key in it (60) whose value is undef.

Finally, %maxBits=map {$_=>60};. This is a syntax error, because map needs a list of values to work with.

I recommend that you stop and read Learning Perl (the Llama book). IIRC (and I admit I've not looked at it in the last several years) it includes a good tutorial on data types - scalars, arrays, hashes. I don't think it includes much on references, but once you've read and understood the Llama you should be able to cope with perlreftut, perldsc, and all the other tutorials that come with perl and, if you still need it, the documentation for the map function.


In reply to Re: initialize all values in a hash by DrHyde
in thread initialize all values in a hash by AWallBuilder

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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-19 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found