Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > enlarge Variablenames

Reply
Thread Tools

enlarge Variablenames

 
 
Ugur Boss
Guest
Posts: n/a
 
      06-15-2004
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

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      06-15-2004
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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      06-15-2004
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


 
Reply With Quote
 
Ugur Boss
Guest
Posts: n/a
 
      06-15-2004
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


 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      06-15-2004
[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
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      06-15-2004
[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


 
Reply With Quote
 
Andrew DeFaria
Guest
Posts: n/a
 
      06-15-2004

"Jürgen Exner" <> wrote in message
news:4gDzc.46771$...
> [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.


 
Reply With Quote
 
gnari
Guest
Posts: n/a
 
      06-16-2004
"Andrew DeFaria" <> wrote in message
news:746e9$40cf68b4$c09cfc9$ rvers.com...
>
> "Jürgen Exner" <> wrote in message
> news:4gDzc.46771$...
> > [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




 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      06-16-2004
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";
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
You can enlarge a tire but you can't enlarge a photo =?iso-8859-1?Q?mark=5Fdigital=A9?= Digital Photography 11 03-08-2006 03:10 AM
How to enlarge Yahoo Chatroom window? Elliott Graham Computer Support 2 07-02-2004 10:12 PM
Icons And Things ENLARGE! Atariki\(riki\) Pole Computer Support 2 10-18-2003 06:27 AM
How to enlarge a 2D polygon (conex, nonconvex) Shamli C Programming 4 10-11-2003 05:43 PM
enlarge control panel listings randy hodge Microsoft Certification 2 07-18-2003 06:38 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57