Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Text::Unaccent::PurePerl undef values

by choroba (Archbishop)
on Mar 18, 2018 at 20:00 UTC ( #1211211=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2020-12-05 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (63 votes). Check out past polls.

    Notices?