foreach $f(@fields) {
$$f = ""; # or use undef, whatever
}
If strict refs is in use this won't work unless you turn them off do the $$f = ""; bit
then turn them back on if stricy refs was in use
So actually ( or somehting like it, I'm in a hurry and may have been sloppy )...
foreach $f(@fields) {
no strict 'refs';
$$f = "";
if(strict refs were on before) { use strict 'refs'; }
}
...Would be better, not sure exactly how to tell if 'strict refs were on before' but
I'm sure there's a way.
Dan
-----Original Message-----
From: Joe Mecklin [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 13, 2003 11:00 AM
To: [EMAIL PROTECTED]
Subject: reference problem (i think)
i'm building a routine in a module (ISD.pm) that will clear a list of variables (set
them to ""), with the intent of expanding the functionality further in the future.
when called, the sub is passed a list of strings that are variable names without the
leading "$".
my goal is to append the "$" to each string (school_id becomes $school_id, etc) then
set $school_id = "".
the expanded functionality is to allow a single argument to a sub be used as the
variable name and the CGI param() argument since i tend to use the same name for each
component.
the call:
&ISD::clear_input(FIELDS => "school_id, school_name, school_address");
the sub:
# CLEAR_INPUT
# takes a list of variables (w/o the "$") to clear to an empty string
sub clear_input
{
my %options = @_;
my $fields = $options{FIELDS};
my (@field) = split /, /, $fields;
foreach my $current_field (@field)
{
my $field_name = "\$" . $current_field;
my $field_value = \$field_name;
print "\$current_field = .$current_field. : \$field_name = $field_name = ." .
\$field_value . ". <br />";
print "\$current_field = .$current_field. = ." . ${field_name} . ". <br />";
}
}
currently the routine only prints out the values that are passed and subsequently
constructed on the fly.
these are the values printed out:
$current_field = .school_id. : $field_name = $school_id = .REF(0x8280b90).
$current_field = .school_id. = .$school_id. $current_field = .school_name. :
$field_name = $school_name = .REF(0x8280b90). $current_field = .school_name. =
.$school_name. $current_field = .school_address. : $field_name = $school_address =
.REF(0x8280b90). $current_field = .school_address. = .$school_address.
obviously i'm missing the boat somewhere along the way (if i'm even on the right
river); how can i accomplish what i want to do?
thanks,
joe
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]