in reply to XML::RSS save crashing

It looks like someone (you?) is sensibly using use strictures; or use warnings FATAL => 'all'; somewhere.

Where is $text coming from? My gut reaction is that you are unexpectedly assigning a value of undef to it somewhere, possibly thinking you have an empty string instead. If you are in fact making the assignment in your code you might try this: my $text = $some_str || ''; to ensure a defined value if an empty string is acceptable.

If it is not, then you need to find out why the data is coming in as undef to begin with.

Thinking about it further, I suspect you are passing $some_str as a parameter to a method. You could still use the $some_str || '' construct, but it feels more like you should track down why that is undef to begin with.

You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Replies are listed 'Best First'.
Re^2: XML::RSS save crashing
by afoken (Chancellor) on May 11, 2015 at 09:46 UTC
    $text = $some_str || ''

    Please note that the defined-or operator is //, not ||. $text = $some_str || '' silently converts 0 to the empty string due to boolean evaluation of $some_str, causing even more subtile bugs.

    The defined-or operator was introduced in perl v5.10. For older perl versions, you need to use something like $text=defined($some_str) ? $some_str : ''.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)