in reply to Any idea what this does

It needlessly uses slices.
@{$memoryfile}[0]
would be less misleading as
${$memoryfile}[0]
and I think it would be more readable as
$memoryfile->[0]

Replies are listed 'Best First'.
Re^2: Any idea what this does
by blazar (Canon) on May 29, 2007 at 09:21 UTC
    It needlessly uses slices.

    Using a (single) slice I would probably do:

    for (@{$memoryfile}[0,1]) { LogMess("Error: Binary input data detected",1), return -1 if /[^[:print:]]/; }

    Somewhat of an overkill for just two values, but IMHO clearer and also easy to modify if you want something more than 0 and 1 there...

      I would probably do this:

      my $has_unprintable_re = qr{ [^[:print:]] }x; if ( grep { /$has_unprintable_re/ } @{$memoryfile}[0,1] ) { LogMess( 'Error: Binary input data detected', 1 ); return -1; }
      , even though your for&if does the same thing as my if&grep.

      My first reading of your code made me say "Hmmm, it could print the error twice... {Re-reading} Oh, wait, the LogMess and the return are in the same statement, and the return will (of course) exit the loop."

        My first reading of your code made me say "Hmmm, it could print the error twice... {Re-reading} Oh, wait, the LogMess and the return are in the same statement, and the return will (of course) exit the loop."

        Indeed, one tiny difference between my approach and yours is that the latter will always iterate on all (both, in this case) items while the former will exit early. Of course I didn't mention "performance" and I was not thinking of it. Do not even dare to suppose I had the slightest idea of micro-optimizing! ;-)