in reply to trouble modifying add_record subroutine
foreach $field (@fields){ ${$field} = $q->param($field); ${$field} = filter(${$field}); $record .= "\::${$field}"; }
First off, unless you really need to save the $field data for later, you don't need to setup the ${$field} variables. You could do...
foreach $field (@fields) { $temp = $q->param($field); $temp = filter($temp); $record .= "\::$temp"; }
Secondly, If you did need to save the data as such for some reason... Use a hash.
foreach $field (@fields) { $data{$field} = $q->param($field); $data{$field} = filter($data{$field}); $record .= "\::$data{$field}"; }
The person who helped me learn perl told me "If you're dealing with data, always ask How can I use a hash here?"
|
---|