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:  <%-{-{-{-<