Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Check for hash ref emptiness

by NetWallah (Canon)
on Feb 07, 2018 at 21:53 UTC ( [id://1208653]=note: print w/replies, xml ) Need Help??


in reply to Check for hash ref emptiness

The regex check will do nothing if the value is empty, so your 'if' check is unnecessary.

Instead of checking for 'empty', you should be checking 'defined-ness' - which , for a hash uses 'exists':

if ( exists $data->{classes} and defined $data->{classes} ){ $data->{classes} =~ s/XY//g; }
UPDATE: Added 'defined' check, per comment by AnomalousMonk(++), below.

                Python is a racist language what with it's dependence on white space!

Replies are listed 'Best First'.
Re^2: Check for hash ref emptiness
by AnomalousMonk (Archbishop) on Feb 07, 2018 at 22:49 UTC
    ... you should be checking 'defined-ness' - which , for a hash uses 'exists' ...

    A hash key may exist and its value be undefined. If it is undefined, a warning will be produced by an operation like matching if warnings are enabled — as we hope they (almost) always are! See exists.


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1208653]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-16 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found