Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Oh I agree about strict and warnings - but, frankly, I'm not sure that warning would have helped alot. 'Cause if the problem is that the " = 1" in
while ($book_id = $sth->fetchrow_array()) { $booklist_1{$book_id} = 1; }
creates a reference to %1, then why doesn't using something other than "1" correct the problem?

I mean, I just want to set the value of a hash element to one.

I love Perl - it's responsible for most of my personal income and written into most of my work by choice - so don't get me wrong on this next statement - but on a rare occasion Perl does really make me shake my head. It's not like I'm trying to invent calculus here. I just want to set the value of a hash element to 1 then recall the key. It shouldn't take strict and warnings and an in-depth discussion of special variables and references and most of the afternoon...this sort of thing is just ammunition for the anti-Perl crowd...ok, venting off...

By the way, using {} did make the script work correctly, with the sole exception that now $booklist_1{$book_id} equals 'HASH(0x8529f88)' - which is not a problem, per se, since I don't use it, but it seems a very messy result.




Time flies like an arrow. Fruit flies like a banana.

In reply to Re^6: Why is my code assigning the last-retrieved value to all elements in my hash? by punch_card_don
in thread Why is my code assigning the last-retrieved value to all elements in my hash? by punch_card_don

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 romping around the Monastery: (4)
As of 2024-04-24 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found