Re: SOLVED: How do I scope a variable if the variable name contains a variable?

From: Uri Guttman (uri_at_stemsystems.com)
Date: 05/21/04


Date: Thu, 20 May 2004 23:52:52 GMT


>>>>> "DF" == David Filmer <IneverReadAnythingSentToMe@hotmail.com> writes:

  DF> The fact that my last posting seems very clear to me but not to you is
  DF> troubling. Either I have it right but am expressing it poorly, or I
  DF> have it wrong. I believe I'm clearly expressing my understanding of
  DF> the subject, so I wonder if my understanding is all wrong. Please
  DF> allow me to briefly summarize my understanding, and prehaps you will
  DF> be kind enough to point out where I've gone astray.

>>> show some code. your words are not conveying much useful info.

  DF> The code is at the top of the post. You didn't like it. You were
  DF> right. I don't have any better code to post, because, as I understand
  DF> it, what I was trying to do cannot be done (and thus cannot be coded),
  DF> and I need to do something else.

symrefs CAN be done but they are nasty and evel and not needed for
general purpose data handling as you are doing.

  DF> What I was trying to do was use a variable-as-a-variablename, and my
  DF> original question was how I could properly scope it, because

  DF> my $foo = 'bar';
  DF> my @{$foo}; #ie, @bar

  DF> doesn't work. I thought it was a syntax problem.

use strict rightly disallows that.

  DF> What I believe you've said (and what I've concluded) is that it cannot
  DF> be done at all (at least not without unleashing the demons of hell).
  DF> It is flat-out impossible to scope a variable (with a 'my' statement)
  DF> if the variable is not a hard reference. Is my understanding of this
  DF> correct?

well, your wording is not perfect. my variables are not in the symbol
table so you can't get access to them via symrefs (even if they are allowed).

  DF> You suggested using a hash INSTEAD of an array, correct? But I can't
  DF> do that, because I'm trying to pass this object to a module
  DF> (HTML::Template) which expects an array, ie:

i meant use a hash instead of a symref (which is really using the symbol
table as a hash).

  DF> $template->param(THIS_LOOP => \@loop_data);

  DF> So I need to rewrite a section of my code to use a hard reference
  DF> (ie, @bar) instead of a symref (@{$foo} #where $foo eq 'bar'), and
  DF> there's no way around that (without unleashing the demons). Is
  DF> this correct?

i don't understand the problem. the param wants an array ref. the ref
could come from any array variable or be an anon array with []. this has
nothing to so with symrefs or hashes. you don't seem to understand perl
hard references. read perlreftut and perlref.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


Relevant Pages

  • Re: SOLVED: How do I scope a variable if the variable name contains a variable?
    ... Either I have it right but am expressing it poorly, ... so I wonder if my understanding is all wrong. ... What I was trying to do was use a variable-as-a-variablename, ... You suggested using a hash INSTEAD of an array, ...
    (comp.lang.perl.misc)
  • Need help understanding an Array push
    ... complex script that generates some reports based on some text input ... Need help understanding what this section of Perl code does: ... new arrangement of the data pulled out of the other array. ...
    (comp.lang.perl.misc)
  • RE: Byte Array Question
    ... "mikebres" wrote: ... I'm not a VB.Net programmer and I don't know what the double greater than ... Binary Field is being placed into the byte Array in preparation to be ... if you have any references I could study to get a better understanding ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SOLVED: How do I scope a variable if the variable name contains a variable?
    ... Symrefs don't work under use strict. ... This is not a hard reference... ... this is just an array variable. ... Here the members of the hash are references to arrays, ...
    (comp.lang.perl.misc)
  • Re: [PATCHv2] drivers/misc: Altera Cyclone active serial implementation
    ... ARRAY_SIZEis not relevant to the understanding of this ... this array is of that length. ... I don't think anything else can change ppos. ... My original rationale was to skip the delay in case of error, ...
    (Linux-Kernel)