On Thu, Oct 16, 2008 at 03:45:02PM -0400, Uri Guttman wrote:
> working around strict when you don't need to is a bad idea as well. as i
> said before symrefs are for when you have to mung the symbol table. no other
> uses should be allowed. there is no need for this. the OP needs to learn
> to use
> "JM" == Jeremy Muhlich <[EMAIL PROTECTED]> writes:
JM> If you restrict your 'no strict' to a very small block, it's really no
JM> problem at all. Best practice is to apply it to the smallest possible
JM> block possible. This would be even better than what I initially wrote:
JM>
> "JM" == Jeremy Muhlich <[EMAIL PROTECTED]> writes:
JM> One kind of nasty option is to use string eval:
JM> $varname = "\$${_}_type";
JM> eval "$varname = ";
JM> There are technical caveats and perhaps moral issues with this approach,
JM> but it works.
that is like telling a k
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]; boston-pm@mail.pm.org
> 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 & other
If you restrict your 'no strict' to a very small block, it's really no
problem at all. Best practice is to apply it to the smallest possible
block possible. This would be even better than what I initially wrote:
foreach ... {
# "setup" code here
{
no strict 'refs';
$$varnam
o: 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:
> >
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.p
One kind of nasty option is to use string eval:
$varname = "\$${_}_type";
eval "$varname = ";
There are technical caveats and perhaps moral issues with this approach,
but it works.
-- Jeremy
On Thu, 2008-10-16 at 08:32 -0600, Palit, Nilanjan wrote:
> How (or can) I use an interpolated s
> "PN" == Palit, Nilanjan <[EMAIL PROTECTED]> writes:
PN> I was hoping there was a way around that still satisfied 'strict refs'.
that is the whole point of strict refs, to disallow using a string for a
variable name. there are many reasons this is a good thing and your
trying to work aroun
[Boston.pm] Interpolated scalar as an lvalue?
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
> tes
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
How (or can) I use an interpolated scalar as an lvalue?
Example: I want to assign a value to a bunch of scalar variables $_type:
my ($abc_type, $def_type, $xyz_type);
...
...
foreach (qw(abc def xyz)) #List of prefixes
{
$varname= $_."_type"; #Actual scalar variable name is $prefix_type
12 matches
Mail list logo