Home  |  Linux  | Mysql  | PHP  | XML
From:Steve Bertrand Date:Thu Jul  2 23:46:44 2009
Subject:More compact way to write this
Hi all,

I've been toying with different techniques in how to make this code more
compact. I have a few sanity checks like this, but against different
incoming fields.

The problem I have, is that I don't like the fact that the "if"
condition contains the exact same line of code that a sub-section of the
add_message() function is receiving as a parameter. I know there is a
way to bundle it better, but in my testing, I haven't been able to do it.

While it may likely be mostly irrelevant, the code below is operating
within the namespace of an object in the third level of the call stack.
It has been passed a string to test (which gets copied into %$data), and
an Error object which it must update if necessary. (I hope the code
renders properly in the email).

# item name

if (length($data->{item_name}) == 0) {
$error->add_message( "item_name is undefined" );
}
if ($self->safe_string($data->{item_name})) {
$error->add_message( "item_name has potentially dangerous chars:".
$self->safe_string($data->{item_name})
);
}

Steve

ps. I'm currently working on a hash within my Vars class that will map
names to error messages (and types).

Navigate in group perl.beginners at sever nntp.perl.org
Previous Next


Your recent visits
Re: sequential value check
Re: sequential value check
Re: Substitution question
sorting anonymous arrays inside arrays
Perl script to monitor memory usage on unix box



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants