Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   enlarge Variablenames (http://www.velocityreviews.com/forums/t886896-enlarge-variablenames.html)

Ugur Boss 06-15-2004 01:26 PM

enlarge Variablenames
 
my Problem ist following:

$nr1 = 1;
$nr2 = 2;

$name.$nr = "Hello";

I have tried following way:

${"name".$nr} = "Hello";

But it doesn´t work. Is there another way to solve my problem?

greetings


Paul Lalli 06-15-2004 01:34 PM

Re: enlarge Variablenames
 
On Tue, 15 Jun 2004, Ugur Boss wrote:

> my Problem ist following:
>
> $nr1 = 1;
> $nr2 = 2;
>
> $name.$nr = "Hello";
>
> I have tried following way:
>
> ${"name".$nr} = "Hello";
>
> But it doesn´t work. Is there another way to solve my problem?


You haven't described what your problem is. What exactly are you trying
to achieve?

Note that I'm going to make a *guess* that you are trying to use a
variable as a variable name. This is A Bad Idea. For more information on
why this is A Bad Idea, and how to do what you *should* do instead, please
read the FAQ entry "How can I use a variable as a variable name":

perldoc -q 'variable name'

Paul Lalli

Jürgen Exner 06-15-2004 01:44 PM

Re: enlarge Variablenames
 
Ugur Boss wrote:
> my Problem ist following:
>
> $nr1 = 1;
> $nr2 = 2;
>
> $name.$nr = "Hello";


This is not Perl. Are you thinking about a "record" like in Modula or
Pascal?
The closest Perl data structure would be a hash:
$name{$nr} = "Hello";

jue



Ugur Boss 06-15-2004 01:46 PM

Re: enlarge Variablenames
 
I try to enlarge the variablename of my scalar $name so that i have
later a variable named $name666 or $name999 with the value "Hello".


Paul Lalli schrieb:

> On Tue, 15 Jun 2004, Ugur Boss wrote:
>
>
>>my Problem ist following:
>>
>> $nr1 = 999;
>> $nr2 = 666;
>>
>> $name.$nr = "Hello";
>>
>>I have tried following way:
>>
>> ${"name".$nr} = "Hello";
>>
>>But it doesn´t work. Is there another way to solve my problem?

>
>
> You haven't described what your problem is. What exactly are you trying
> to achieve?
>
> Note that I'm going to make a *guess* that you are trying to use a
> variable as a variable name. This is A Bad Idea. For more information on
> why this is A Bad Idea, and how to do what you *should* do instead, please
> read the FAQ entry "How can I use a variable as a variable name":
>
> perldoc -q 'variable name'
>
> Paul Lalli



Paul Lalli 06-15-2004 01:52 PM

Re: enlarge Variablenames
 
[please post your replies *below* the text you are replying to]

On Tue, 15 Jun 2004, Ugur Boss wrote:

> Paul Lalli schrieb:
>
> > On Tue, 15 Jun 2004, Ugur Boss wrote:
> >
> >
> >>my Problem ist following:
> >>
> >> $nr1 = 999;
> >> $nr2 = 666;
> >>
> >> $name.$nr = "Hello";
> >>
> >>I have tried following way:
> >>
> >> ${"name".$nr} = "Hello";
> >>
> >>But it doesn´t work. Is there another way to solve my problem?

> >
> >
> > You haven't described what your problem is. What exactly are you trying
> > to achieve?
> >
> > Note that I'm going to make a *guess* that you are trying to use a
> > variable as a variable name. This is A Bad Idea. For more informationon
> > why this is A Bad Idea, and how to do what you *should* do instead, please
> > read the FAQ entry "How can I use a variable as a variable name":
> >
> > perldoc -q 'variable name'
> >
> > Paul Lalli

>
> I try to enlarge the variablename of my scalar $name so that i have
> later a variable named $name666 or $name999 with the value "Hello".
>


Yes. This is what I said. You are trying to use a variable (in this case
$nr1 or $nr2) as part of a variable name. This is not a good idea.
Please read the FAQ I mentioned in my previous reply. If you do not
understand something in that FAQ, let us know what you don't understand.

Paul Lalli

Jürgen Exner 06-15-2004 01:58 PM

Re: enlarge Variablenames
 
[Please do not top-post]
[Please trim the quoted text to a reasonble amout that is needed for
context]
Ugur Boss wrote:
> I try to enlarge the variablename of my scalar $name so that i have
> later a variable named $name666 or $name999 with the value "Hello".


This is A Bad Idea.
Please see 'perldoc -q "variable name"' why and what to do instead.

jue



Andrew DeFaria 06-15-2004 09:23 PM

Re: enlarge Variablenames
 

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:4gDzc.46771$TR1.20338@nwrddc01.gnilink.net...
> [Please do not top-post]
> [Please trim the quoted text to a reasonble amout that is needed for
> context]


Also, aren't these top posts? ;-)

Not I whole heartedly agree with Jügen, trim, trim, trim! Way too much
excess is quoted.



gnari 06-16-2004 08:07 AM

Re: enlarge Variablenames
 
"Andrew DeFaria" <Andrew@DeFaria.com> wrote in message
news:746e9$40cf68b4$c09cfc9$28691@msgid.meganewsse rvers.com...
>
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:4gDzc.46771$TR1.20338@nwrddc01.gnilink.net...
> > [Please do not top-post]
> > [Please trim the quoted text to a reasonble amout that is needed for
> > context]

>
> Also, aren't these top posts? ;-)


not really. these were general comments that did not depend on any
quoted text. Jürgen could have stopped there but decided to
also reply to the top-poster, and did that properly quoted, of
course

gnari





Joe Smith 06-16-2004 10:15 AM

Re: enlarge Variablenames
 
Ugur Boss wrote:

> my Problem ist following:
>
> $nr1 = 1;
> $nr2 = 2;
>
> $name.$nr = "Hello";


my %name; # Use a hash
$name{666} = "Number of the beast";
$name{foo} = "bar";
$name{$nr1} = "one";
$name{$nr2} = "two";


All times are GMT. The time now is 02:01 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.