RE: generating arrays on the fly

2002-08-28 Thread Bob Showalter

> -Original Message-
> From: Ramprasad A Padmanabhan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 28, 2002 1:27 AM
> To: [EMAIL PROTECTED]
> Cc: Ramprasad A Padmanabhan; [EMAIL PROTECTED]
> Subject: Re: generating arrays on the fly
> 
> 
> Thanx
>   I am not a great master of perl , but have been getting my job done
> with perl for the past 2 years. Can u educate me why I cant 
> do 'symbolic
> references' in eval('@' .$1 .' = () ')

You "can" do it, even without eval(). But you definitely "shouldn't" do it.

Suppose $1 contain 'INC' or 'ISA' or 'ARGV', and your program makes use of
those. Your eval just zapped them.

This kind of thing is why programs that "work fine" will suddenly,
unexpectedly, break in mysterious ways months later.

Resist the temptation.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: generating arrays on the fly

2002-08-27 Thread Dharmendra Rai


Hi ,

The name of the global var is put into symtab during compilation while that of local 
var is converted to its offset. So if u want to "NAME" a var at run-time, u won't 
succeed. All u can do is that use hash-table with the KEYNAMES as those words 
appearing in the file.

  Read about the things happening at run and compile time and rest of ur doubts will 
just vanish

 




-
Get a bigger mailbox -- choose a size that fits your needs.

http://uk.docs.yahoo.com/mail_storage.html


Re: generating arrays on the fly

2002-08-27 Thread Sudarshan Raghavan

On 28 Aug 2002, Ramprasad A Padmanabhan wrote:

> Thanx
>   I am not a great master of perl , but have been getting my job done
> with perl for the past 2 years. Can u educate me why I cant do 'symbolic
> references' in eval('@' .$1 .' = () ')

This does not just apply for eval, symbolic references should avoided in 
all places. http://perl.plover.com/varvarname.html



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: generating arrays on the fly

2002-08-27 Thread Ramprasad A Padmanabhan

Thanx
  I am not a great master of perl , but have been getting my job done
with perl for the past 2 years. Can u educate me why I cant do 'symbolic
references' in eval('@' .$1 .' = () ')


On Wed, 2002-08-28 at 03:31, Jeff 'japhy' Pinyan wrote:
> On Aug 27, Ramprasad A Padmanabhan said:
> 
> >> if ($line=~(/^\[\[(\w+)\]\]/)){
> >> @$1=();   #this is the line I want to acheive my aim with!
> >> }
> >
> >  if ($line=~(/^\[\[(\w+)\]\]/)){
> >  eval('@' .$1 .' = () ') || warn $@
> >  }
> 
> First, don't do that.  You're doing symbolic references in effect.
> Second, that eval() returns 0 (the size of the array), and thus you will
> get warned for no reason.
> 
> -- 
> Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
> RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
> ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
>  what does y/// stand for?   why, yansliterate of course.
> [  I'm looking for programming work.  If you like my work, let me know.  ]
> 
-- 
Ramprasad A Padmanabhan
Sr Software Engineer
Netcore Solns Pvt Ltd
Mumbai
ph - (022) 4628000


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: generating arrays on the fly

2002-08-27 Thread Jeff 'japhy' Pinyan

On Aug 27, Ramprasad A Padmanabhan said:

>> if ($line=~(/^\[\[(\w+)\]\]/)){
>> @$1=();   #this is the line I want to acheive my aim with!
>> }
>
>  if ($line=~(/^\[\[(\w+)\]\]/)){
>  eval('@' .$1 .' = () ') || warn $@
>  }

First, don't do that.  You're doing symbolic references in effect.
Second, that eval() returns 0 (the size of the array), and thus you will
get warned for no reason.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: generating arrays on the fly

2002-08-27 Thread Bob Showalter

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 27, 2002 9:57 AM
> To: [EMAIL PROTECTED]
> Subject: generating arrays on the fly
> 
> 
> hi,
> 
> what I'm wanting to do is generate an array named after a 
> string that is
> found in a text file.
> 
> i.e something like this:
> if ($line=~(/^\[\[(\w+)\]\]/)){
> @$1=();   #this is the line I want to acheive my aim with!
> }
> 
> I know the syntax is wrong, but hopefully it explains what 
> I'm trying to
> do, any clues?

No, you don't want to do that. Suppose the string in your text file is INC
or ISA. You'll trash those global arrays, or perhaps other arrays in your
script.

Use a hash to hold these arrays instead. The hash keys can be the names from
your file. Then you're safe.

my %h;

if ($line=~(/^\[\[(\w+)\]\]/)){
   $h{$1} = []; # initalize to an empty array
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: generating arrays on the fly

2002-08-27 Thread Nikola Janceski

perhaps a hash of arrays is what you want:

if ($line=~(/^\[\[(\w+)\]\]/)){
$HASH{$1} = [];
}


and you reference the array like

push @{ $HASH{'text'} }, "someinfo";

or anyother array functions.

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 27, 2002 9:57 AM
> To: [EMAIL PROTECTED]
> Subject: generating arrays on the fly
> 
> 
> hi,
> 
> what I'm wanting to do is generate an array named after a 
> string that is
> found in a text file.
> 
> i.e something like this:
> if ($line=~(/^\[\[(\w+)\]\]/)){
> @$1=();   #this is the line I want to acheive my aim with!
> }
> 
> I know the syntax is wrong, but hopefully it explains what 
> I'm trying to
> do, any clues?
> 
> thanks,
> Adrian
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: generating arrays on the fly

2002-08-27 Thread Ramprasad A Padmanabhan

[EMAIL PROTECTED] wrote:
> hi,
> 
> what I'm wanting to do is generate an array named after a string that is
> found in a text file.
> 
> i.e something like this:
> if ($line=~(/^\[\[(\w+)\]\]/)){
> @$1=();   #this is the line I want to acheive my aim with!
> }
> 
> I know the syntax is wrong, but hopefully it explains what I'm trying to
> do, any clues?
> 
> thanks,
> Adrian
> 
> 
> 

use eval
  if ($line=~(/^\[\[(\w+)\]\]/)){
  eval('@' .$1 .' = () ') || warn $@
  }


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]