http://qs321.pair.com?node_id=1211211


in reply to Text::Unaccent::PurePerl undef values

With 5.10+, you can use the defined-or operator:
@$ResultsFinal = sort { unac_string($a->[$OptOrderToDisplayTable] // " +") cmp unac_string($b->[$OptOrderToDisplayTable] // " +") } @$ResultsFinal );
In older Perls, you need to be more verbose:
unac_string( defined $a->[$OptOrderToDisplayTable] ? +$a->[$OptOrderToDisplayTable] : "")

Update: Fixed the code. If you had provided SSCCE, I could've tested my code :-)

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Text::Unaccent::PurePerl undef values
by IB2017 (Pilgrim) on Mar 18, 2018 at 22:22 UTC

    Thank you for your suggestion. Unfortunately it does not solve the problem. I do not quite understand the map you propose as to me it does not seem to apply to the elements of the array I use to sort. Here a dump of the @ResultsFinal (3 records) before and after the sorting. If sorting for $OptOrderToDisplayTable=4, for example, you can see that the corresponding element of $VAR3 still remains undef . This fires an error by unac_string . Am I overseeing something in your code?

    $VAR1 = [ 841, 'bbb', '', 'bbb', 'bbb', undef, undef, undef, '', '' ]; $VAR2 = [ 842, 'bbb', '', 'ccc', 'aaa', undef, undef, undef, '', '' ]; $VAR3 = [ 850, 'bbb', '', 'hhh', undef, undef, undef, undef, '', '' ]; ###After $VAR1 = [ 841, 'bbb', '', 'bbb', 'bbb', undef, undef, undef, '', '' ]; $VAR2 = [ 842, 'bbb', '', 'ccc', 'aaa', undef, undef, undef, '', '' ]; $VAR3 = [ 850, 'bbb', '', 'hhh', undef, undef, undef, undef, '', '' ];
      Sorry, fixed.
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^2: Text::Unaccent::PurePerl undef values
by IB2017 (Pilgrim) on Mar 18, 2018 at 23:13 UTC

    Thank you. This works like a charm. You use some operators I never used before :( so I learned something new too. Sorry for not having posted a complete example with data. Next time I'll certainly do.