Roland Corbet wrote:
> I have a program that contains a subroutine that populates
> variables from name-value pairs passed to it from an HTML form.
>
> I want to improve my scripts by defining my variables using the 'my'
> function and perhaps 'use strict;'. I don't think that I can
> use the full function of strict because my code has to use
> symbolic references in order to make the dynamic variable names.
> For example:
>
> $$VARNAME = $PAIR_DATA;
>
> AFAIK, there's no other way around this that will work with
> strict.
True. But consider using a hash instead of dynamic variable names:
my %var;
$var{$VARNAME} = $PAIR_DATA;
> So, I'll probably be limited to:
>
> use strict "vars";
> #use strict "refs";
> use strict "subs";
Aka "use strict qw(vars subs);".
> Having to define all variables using 'my' poses a problem when the
> variables are created within the subroutine. Once I try to
> reference them outside the subroutine I will get a warning saying
> that I have not defined the variable. Obviously doing a 'my' when
> the variable is created in the subroutine would not be of any use
> (only available inside the sub). Is there perhaps a way to define
> the dynamic variable as being a global value?
Well, you can define the variable outside the subroutine and *initialise* it
inside the function -- that is, have a "my $var;" at the outermost level.
Or, of course, you could "use vars qw($var);". This would create a real
package variable.
Cheers,
Philip
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web