A better way to do this is something like
foreach my $aref (["abc", \$abc], ["def", $def], ["ijk", $ijk])
{
my ($name, $sref) = @$aref;
$$sref = ....
}
which gives you the variable name string and a reference to it in each
iteration of the loop.
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]; [email protected]
> Date: Thu, 16 Oct 2008 12:25:02 -0600
> Subject: Re: [Boston.pm] Interpolated scalar as an lvalue?
>
> I didn't know that usage model for strict refs. Thanks!
>
> Though, as you & others said, the moral issues still remain with that!
>
> -Nilanjan
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeremy Muhlich
> Sent: Thursday, October 16, 2008 2:02 PM
> To: boston-pm
> Subject: Re: [Boston.pm] Interpolated scalar as an lvalue?
>
> On Thu, 2008-10-16 at 10:39 -0400, Ronald J Kimball wrote:
> > On Thu, Oct 16, 2008 at 08:32:41AM -0600, Palit, Nilanjan wrote:
> >
> > > Perl complains about the second line in the foreach loop during run time:
> > > Can't use string ("abc_type") as a SCALAR ref while "strict refs" in use
> > > at test1.pl line 19.
> > >
> >
> > The error message explains exactly what the problem is. You can't use
> > strings as refs while "strict refs" is in use. If you want to use strings
> > as refs, turn off "strict refs".
> >
> > no strict 'refs';
>
> Actually Nilanjan, you can just turn off strict refs inside the block
> where you write your new code. No need to turn it off for the entire
> program.
>
> foreach ... {
> no strict 'refs';
> $$varname = <something>
> }
> # refs are still strict out here
>
>
> -- Jeremy
>
>
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/boston-pm
>
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/boston-pm
_________________________________________________________________
Stay organized with simple drag and drop from Windows Live Hotmail.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_102008
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm