Re: Any idea what this does
by ikegami (Patriarch) on May 29, 2007 at 03:00 UTC
|
It needlessly uses slices.
@{$memoryfile}[0]
would be less misleading as
${$memoryfile}[0]
and I think it would be more readable as
$memoryfile->[0]
| [reply] [d/l] [select] |
|
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... | [reply] [d/l] |
|
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."
| [reply] [d/l] [select] |
|
Re: Any idea what this does
by ysth (Canon) on May 29, 2007 at 02:39 UTC
|
| [reply] |
Re: Any idea what this does
by swampyankee (Parson) on May 29, 2007 at 10:35 UTC
|
Is this a quiz?
The regex, itself, is an example of an IEEE Std 1003.1, also known as POSIX character class syntax; see perlre, which states [:print:] is "Any alphanumeric or punctuation (special) character or the space character." The [^] syntax is normal regex syntax, so in this case, the regex will return true if any character which is not in the list of what [:print:] considers "printable" is found either array element.
The @{...}...appears to be an (possibly incorrectly written) dereferencing; I don't think it's relevant to the question.
emc
Any New York City or Connecticut area jobs? I'm currently unemployed.
There are some enterprises in which a careful disorderliness is the true method.
—Herman Melville
| [reply] |
|
| [reply] |
Re: Any idea what this does
by jesuashok (Curate) on May 29, 2007 at 01:42 UTC
|
If the first character of @{$memoryfile}[0] or (||) @{$memoryfile}[1] is not a printable character then log a error message and returns -1 value. | [reply] [d/l] [select] |
|
| [reply] [d/l] |
|
No. If *any* character.
And what's with "(||)"?
| [reply] |
|
He's explaining that "||" means "or".
| [reply] |
|
Also I feel LogMess must be some subroutine somewhere in the code, which accepts two arguments.
| [reply] |