[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] simple syntax question




On Jul 28, 2004, at 9:36 PM, Hugh Jarce wrote:
Ryan Stille wrote:
$tmp1 = $FORM->param('respond_email');
$tmp2 = $FORM->param('name');
$tmp1 =~ s/\n|\r//g;
$tmp2 =~ s/\n|\r//g;
$FORM->param(-name=>'respond_email',-value=>$tmp1);
$FORM->param(-name=>'name',         -value=>$tmp2);

I suppose you could hide the temporary in a function like this:

sub remove_newlines {
    my $t = shift;
    $t =~ tr/\r\n//d;
    return $t;
}

allowing you to write code like this (untested):

$FORM->param(-name  => 'name',
             -value => remove_newlines( $FORM->param('name') ) );

Or even something like

foreach ($FORM->param) {
   my $t = $FORM->param($_);
   $t =~ tr/\r\n//d;
   $FORM->param($_, $t);
}

j