in reply to Re: noob regexpression question
in thread noob regexpression question

The || '' doesn't help, and you'll fail for "foodll".
... my $extension = substr($element, -3) || ''; if ( $extension eq 'exe' ) { ... elsif ( $extension eq 'dll' ) ...
should be
... my $extension = substr($element, -4); if ( $extension eq '.exe' ) { ... elsif ( $extension eq '.dll' ) ...

Replies are listed 'Best First'.
Re^3: noob regexpression question
by polettix (Vicar) on Nov 07, 2005 at 23:55 UTC
    D'ho, lucky me that I put the big "untested code" :) I was convinced that the substr function would return undef if the string was empty (like the middle element in "ciccio.exe,,pallo.dll"), but it is simply the empty string.

    I could agree on the second correction, but only on a robustness ground that seems not necessary in this case. Anyway, better being overprotective, especially when it's cheap and helps building the right attitude.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.