in reply to Re: Initialize or Match undef without warning
in thread Initialize or Match undef without warning

That! Solved the problem.

It also created a problem. I had remarked out the assignment later on in the code. After adding it back in. It has made some of the fields undefined again. I think I need an OR in the extract regex now.

# this initializes the field correctly $row->[15] = ''; # This overwrites the empty field with undefined if it doesn't match. ($row->[15]) = $row->[5] =~ /(#[^ ]+)/;

Replies are listed 'Best First'.
Re^3: Initialize or Match undef without warning
by JobC (Acolyte) on Dec 15, 2015 at 00:04 UTC
    # I changed this $row->[15] = ''; ($row->[15]) = $row->[5] =~ /(#[^ ]+)/; # to this and it does what I want $row->[15] = ''; if ($row->[5] =~ /#[^ ]+/) { ($row->[15]) = $row->[5] =~ /(#[^ ]+)/; }

    Is there a better, more compact way to do this that is still easy to read?

      replace:

      $row->[15] = ''; if ($row->[5] =~ /#[^ ]+/) { ($row->[15]) = $row->[5] =~ /(#[^ ]+)/; }

      with (untested):

      ($row->[15]) = $row->[5] =~ /(#[^ ]+/ ? $row->[5] : '';

      more readable, logically? same line as above, but split across a few lines:

      ($row->[15]) = $row->[5] =~ /(#[^ ]+/ ? $row->[5] : '';

      ternary (aka. conditional) operator.