PDA

View Full Version : Redeclare Variable


otuama
02-15-2011, 10:31 PM
Hi all.

I'm sure this has been asked many times and I'm probably going to get a slap on the wrist for asking again but..... how can I redeclare a variable.

For example:

string $arse[] = `ls -sl`;

as the array was created before the objects were, they aren't stored in the array

polySphere;

polyCube;

select -all;

-------

I know all I need to do is put

string $arse[] = `ls -sl`;

after select -all;

but if I want to later refresh the array contents, I'm lazy so would prefer to not type

string $arse[] = `ls -sl`;

or

string $anotherArse[] = `ls -sl`;

I thought all I'd need to do is type something like this

$arse;

or

eval $arse;

And that would redeclare the string, storing the objects in the array, but no.

I know you're probably thinking 'What a tit!!!' or 'Why doesn't he just copy and paste?' but if it's possible, I'd still like to know.

Thanks,

Sean

pixelranger
02-15-2011, 10:46 PM
string $array[] = { "one", "two", "three" };
print "\nThe array was declared with:\n";
for ($item in $array) print ($item + "\n");

$array = { "four", "five", "six" };
print "\nBut now the array holds:\n";
for ($item in $array) print ($item + "\n");

pixelranger
02-15-2011, 10:48 PM
Or a more "practical" example:

string $array[] = `polySphere`;
print "\nThe array was declared containing:\n";
for ($item in $array) print ($item + "\n");
$array = `polyCube`;
print "\nBut now the array holds:\n";
for ($item in $array) print ($item + "\n");

mduvekot
02-16-2011, 04:06 AM
Note the difference between
string $sel[] = `ls -sl`;


and

string $cmd = "ls -sl";
eval $cmd;

CGTalk Moderation
02-16-2011, 04:06 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.