[27351] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9055 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 15 14:05:37 2006

Date: Wed, 15 Mar 2006 11:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 15 Mar 2006     Volume: 10 Number: 9055

Today's topics:
    Re: Accessing package data through variable <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 15 Mar 2006 09:38:47 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Accessing package data through variable
Message-Id: <slrne1gd86.383.tadmc@magna.augustmail.com>

Amit Brahme <a-brahme@ti.com> wrote:

> 	I want to know if perl can do following thing.


It can, but doing the following is a really really bad idea...


> ------------------------------------------------------------------------
> I've a package and some variables defined in it, like below, in file 
> lets say "junk1.pm".
> 
> ******************
> package junk1;
> $foo = "xyz";
> $abc = "123";
> ******************
> 
> In my program I write a code like
> 
> ******************
> require "junk1.pm";
> $myrf = "junk1";
> print $junk1::foo;
> ******************
> 
> 
> What I want is: instead of using
> 
> print $junk1::foo;
> 
> I want to use $myrf (which is defined as "junk1") to access variable 
> "foo" in package junk1.


Why do you want to use $myrf to access variable "foo" in package junk1?

What is wrong with using $junk1::foo instead?

If we knew what real problem you are trying to solve, we may be
able to help solve it...


You are trying to use "symbolic references", which can lead
to extremely hard-to-find bugs.

There is almost always a better way to accomplish what you need
without symrefs, but we would need to know what you are really
trying to accomplish.


> I tried
> 
> print ${$myrf}::foo;
> 
> but perl gives error for this that it found barework foo. Is there any 
> way I can do something like this?


   print ${$myrf . '::foo'}   # don't do this!

or

   print ${"${myrf}::foo"}  # don't do this either!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9055
***************************************


home help back first fref pref prev next nref lref last post