Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

How to disable:Odd number of elements in hash assignment warning?

by BrowserUk (Patriarch)
on Sep 23, 2016 at 16:04 UTC ( [id://1172468]=perlquestion: print w/replies, xml ) Need Help??

BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

I'm splitting some data into a hash, and occasionally, the last value may be missing.

This is known and unimportant, so I'd like to locally disable that warning; but what category to give to no warnings ...?

(And for bonus points, how to find it?)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re: How to disable:Odd number of elements in hash assignment warning?
by hippo (Bishop) on Sep 23, 2016 at 16:08 UTC

    Hidden in the doc for warnings is this:

    To determine which category a specific warning has been assigned to see perldiag.

    And in perldiag it says:

    Odd number of elements in hash assignment

    (W misc) You specified an odd number of elements to initialize a hash, which is odd, because hashes come in key/value pairs.

    So, the answer would seem to be "misc".

      the answer would seem to be "misc".

      That indeed does it. Thank you.

      And especially thankyou for the pointer to perldiag. I may have been in there at some point in the past, but I do not recollect it.

      I'd looked at the perllexwarn, and the warnings pages, but neither (of the version of perl I was referencing) contain any reference to perldiag. I guess I should update the url in the pinned tab I have for the docs in my browser to a newer version.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re: How to disable:Odd number of elements in hash assignment warning?
by Your Mother (Archbishop) on Sep 23, 2016 at 17:24 UTC

    I think disabling warnings for this kind of thing is perfectly fine but this occurs to me as an alternative; not expressing a preference–

    sub crommulate { push @_, undef if @_ % 2; my %bingo = @_; # ... }

      In general I don't see the point in doing extra work to avoid a warning I can simply disable. Especially when, as in this case, the affected code is processing 10s or 100s of millions of records.

      I could, use tr[] or m[] to count the number of delimiters and then the 3rd arg to split to avoid the odd number of returned values, but since the split is already the most costly (cpu) operation, doing the same work twice to avoid a warning I can disable, would be a waste of cycles.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1172468]
Approved by Paladin
Front-paged by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-03-28 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found