How do I scope a variable if the variable name contains a variable?I can do this:
my @bar; #explicit name - fine
but not this:
my $foo = 'bar'; #fine
my @{$foo}; #oops
Perl complains, "Can't declare array dereference..."
Does anybody know the syntax to scope a variable name that includes a variable?
Thanks!
In article <e4c916dd.0405181656.5d92e96e@posting.google.com>, David Filmer wrote:
> I can do this:
>
> my @bar; #explicit name - fine
>
> but not this:
>
> my $foo = 'bar'; #fine
> my @{$foo}; #oops
The above is how you deference...
Variable in a variable nameI have an entry page which can be used to key in data for ten people. My
assigned variables for each field are in line with
$personage1
$personage2
....etc
$personage9
$personage10
and so on. (I have 8 fields for every person, 80 values in all).
To simplify my code and make changes easier I would like to create and use
these variables with a variable "x" in the name
This by recycling the code with $personX in and changing the value of x and
running the code ten times. Probably in some kind of do while loop (fairly
new to php, but I have been using Excel VB for years and am fa...
Variable variable nameSorry for the cryptic subject, but I am trying to do the following (line
numbers first) in a shell script:
15 type=AD
16 file=100000_10000_AD.csv
17 eval $type_10K=( `cat $file` )
I get the following error message:
+ type=AD
+ file=100000_10000_AD.csv
combinetab.sh: line 17: syntax error near unexpected token `('
combinetab.sh: line 17: `eval $type_10K=( `cat $file` )'
Isn't eval supposed to replace $type with AD and then put the contents
of $file in an array names AD_10K?
Thanks for any comments.
-Samik
Samik R. wrote:
> Sorry for the cryptic subject, but I am trying to ...
Variable name of variablesHello, I've a problem! I have to insert in my matlab program a " for "
cycle in wich the name of variables is a function of cycle index so
the name of variables is variable. For Example:
for i=1:n
ALFA i =......
end.
I want to stamp:
ALFA 1=...
ALFA 2=...
.....
ALFA n=...
How can I do?????? Thank u!!!
In article <1179169081.488869.62950@u30g2000hsc.googlegroups.com>,
Molokovellocet <molokovellocet@fastwebnet.it> wrote:
>Hello, I've a problem! I have to insert in my matlab program a " for "
>cycle in wich the name of variables is a func...
Variables in Variable NameThe most basic way to ask my question if there is anyway of doing this
would be a program that did:
Dim test1 = 1
Dim test2 = 2
Dim test3 = 3
for i = 1 to 3
print testi
next i
Well this presents problems because it wont treat the i as a number,
is there anyway of doing this? Thank you.
Eric wrote:
>
> The most basic way to ask my question if there is anyway of doing this
> would be a program that did:
>
> Dim test1 = 1
> Dim test2 = 2
> Dim test3 = 3
>
> for i = 1 to 3
> print testi
> next i
You were close; all you need is brackets:
dim test(3) as integer
test(1) = 1
test(2) = 2
test(3) = 3
for i = 1 to 3
print test(i)
next i
>
> Well this presents problems because it wont treat the i as a number,
> is there anyway of doing this? Thank you.
"Eric" <erickit@bellsouth.net> wrote in message
news:bd7ac0c8.0401260942.bdbdac6@posting.google.com...
> The most basic way to ask my question if there is anyway of doing this
> would be a program that did:
>
> Dim test1 = 1
> Dim test2 = 2
> Dim test3 = 3
>
> for i = 1 to 3
> print testi
> next i
>
> Well this presents problems because it wont treat the i as a number,
> is there anyway of doing this? Thank you.
Not sure of the exact dialect you're looking for but:
DIM test (1 to 3)
test(1)=1
test(2)=2
test(3)=3
for i = 1 to 3
print test(i)
next i
HK
...
adding a variable name to a hash to name is part of the variable nameI have a perl script that I wrote the loops through a list of servers in a
file and I want to create a hash with the server name in it. I want each
server to have its own hash.
for example
$myserver = thor;
hash name
$server_$myserver_name{$some_key}
want to get this hash name
$server_thor_name{$some_key}
How do I get the $myserver name to be interpolated to thor in that line?
I tried this and it failed.
$server_${myserver}_name{$some_key}
-Bobby
Bobby Chamness wrote:
> I have a perl script that I wrote the loops through a list of servers
> in a file and I want to create a hash...
Variable variablesI'm having trouble creating dynamic variables:
for (year=1968:2001)
load (myfile<year>);
value_<year> = foo;
close (myfile<year>);
How do I loop through a large number of annual files and create
distinguishable matrices commonly-named variables?
In other words, I need to create variable variables.
Thanks!
Bruce:
<SNIP several ML evergreens...
two hints:
<http://www.mit.edu/%7Epwb/cssm/matlab-faq_4.html#loopoverfiles>
<http://www.mit.edu/~pwb/cssm/matlab-faq_4.html#evalcell>
us
In article <ef58d33.-1@webcrossing.raydaftYaTP>,
Bruce <fordbw@gmail.com> wrote:
>I'm having trouble creating dynamic variables:
>for (year=1968:2001)
>load (myfile<year>);
>value_<year> = foo;
>close (myfile<year>);
>How do I loop through a large number of annual files and create
>distinguishable matrices commonly-named variables?
>In other words, I need to create variable variables.
You can do that, but are you sure that they must be in seperate
variables? Is there something about the problem such that
a structure would not do?
for year=1968:2001
yearstr = num2str(year);
load( ['myfile', yearstr] );
values.(['value_', yearstr]) = foo;
end
You don't need to close the file because load opens and reads and closes
the file automatically.
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
...
Variables variableHi folks,
Someone know how to make variables variable like in PHP?
It's something like this:
$a =3D 'hi'
$$a =3D 'testing'
echo $hi
'testing'
Regards
--=20
Adriano Monteiro Marques
www.gopython.com.br
py.adriano@gmail.com
I'm FREE... Are you?
(PYTHON powered)
Adriano Monteiro wrote:
> Hi folks,
>
> Someone know how to make variables variable like in PHP?
> It's something like this:
>
> $a = 'hi'
> $$a = 'testing'
> echo $hi
> 'testing'
You are most certainly wanting to use dictionaries.
Or, if you...
Variable for a VariableI doubt this is possible, but thought to ask anyway.
I have a situation where there are 30 arrays (of structures) all in one
module. Each representing a separate tool within the application.
Just for examples sake I'll make up a few:
Hammer(iElements)
Saw(iElements)
Screwdriver(iElements)
...
Drill(iElements)
I have this Select Case that checks a Tool_ID and locates the correct tool
to operate on.
Select Case Tool_ID
Case ID_Hammer
Hammer(iElements).visible = false
Case ID_Saw
Saw(iElements)...
variable in variableGreetings,
in the below script the variable VAR within STR should be substituted
during runtime:
#!/bin/tclsh
variable VAR 0
variable STR "VAR = $VAR"
puts "VAR=$VAR"
puts "STR: $STR"
set VAR 1
puts "VAR=$VAR"
puts "STR: [subst $STR]"
The result is not as expected:
~> t1.tcl
VAR=0
STR: VAR = 0
VAR=1
STR: VAR = 0 <<<--- this should be 1
~>
I'm using tcl-8.2 on linux.
What am I doung wrong?
Thanks for your time and hints,
Wolf
wg <wg1@gmx.net> wrote:
> Greetings,
> in the below script the variable VAR within STR should be substituted
> during runtime:
> #!/bin/tclsh
> variable VAR 0
> variable STR "VAR = $VAR"
> puts "VAR=$VAR"
> puts "STR: $STR"
> set VAR 1
> puts "VAR=$VAR"
> puts "STR: [subst $STR]"
> The result is not as expected:
> ~> t1.tcl
> VAR=0
> STR: VAR = 0
> VAR=1
> STR: VAR = 0 <<<--- this should be 1
> ~>
No, the output is exactly as expected, and 100% inline with the rules
of Tcl. Your second variable line (variable STR "VAR = $VAR") is
substituted once, and only once, when the statement is first processed
by the interpretor, and what is stored in "STR" is the literal string
"VAR = 0". Which is why changing VAR later does not change STR, the
STR variable was al...
variable variablesHello,
is it possible to make first attr variable?
some_object.attr.attr
so instead of attr I could use self.foo which has value "attr"
Thanks!
En Fri, 18 Jun 2010 06:48:34 -0300, someone <petshmidt@googlemail.com>
escribi�:
> is it possible to make first attr variable?
>
> some_object.attr.attr
>
> so instead of attr I could use self.foo which has value "attr"
I think you're looking for getattr:
http://docs.python.org/library/functions.html#getattr
name = "spam"
getattr(some_object, name) == some_object...
Variable in VariableIs it possible to print the the value of a variable in a variable
what i mean:
Declare @test varchar(255)
Declare @foo varchar(255)
Declare @strSQL varchar(255)
set @test = 'Hallo'
Set @foo = '@test'
Print @foo
Set @strSQL = 'SELECT ' + @foo --Expected result is 'Hallo'
exec master..sp_ExecuteSQL @strSQL
How doess it work?
I hope you understand my problem
Thanks
"Michi Albatross" <alber@netdot.ch> wrote in message
news:67ae724b.0410080410.5c8ccb59@posting.google.com...
> Is it possible to print the the value of a variable in a variable
...
variable of variable $$, ${ ...hi,
i m trying to find how to access a variable of variable (which is an image)
i want to know the size of the picture
the name of the picture is photo1
next one is photo2, next one is photo3 ...
for ($i=1;$i<$MAX_PHOTOS;$i++)
{
$photo='photo'.$i;
$$photo_size; //don t work
}
thx
"cdt_sylvestre" <cdtEffacercAsly@relayeur.com> wrote in message
news:3ff934d6$0$17130$626a54ce@news.free.fr...
> hi,
>
> i m trying to find how to access a variable of variable (which is an
image)
> i want to know the size of the picture
> the name of the picture is ...
Variable in a VariableHi All,
I have a dataset
data abc;
input a b $ c d;
datalines;
100 c 20 30
200 d 10 40
300 c 23 99
;
in this dataset variable b contains either c or d(other variable
name)
how can i get the value of c or d i.e 20 or 30 from first
observation....
Please let me know
thanks in advance
On Feb 8, 1:32 pm, "sasguy" <addanki...@gmail.com> wrote:
> Hi All,
> I have a dataset
> data abc;
> input a b $ c d;
> datalines;
> 100 c 20 30
> 200 d 10 40
> 300 c 23 99
> ;
> in this dataset variable b contains either c or d(other variable
> name)
> how can...
Variable variables?I have a situation which I 'think' I need to use variable variables and
not sure how to go about it.
I have several <select multiple> elements on a search form with their
names created dynamically and the options created dynamically.
$parent holds the name such as "Women", "Mens" etc..
$c_id holds category_id and is sent off as the 'value' of the option.
This form is self calling and an array is created for the multiple
option selected.
Women => array([0]=>20,[1]=>21,...)
Mens => array([0]=>32,[1]=>35,...)
I a...
Variable into a variableI don't know if I'm saying this right but is it possible to pass a
variable into a variable in matlab?
For example in php you can have a variable named something and by
writting
< $that = 'something'.$number; >
you can use change the variable $number with any number you want and
put for example the variable something1 into $that.
"Iraklis Markelis" <it00139@uom.gr> wrote in message
news:hgs1mrxsczak@legacy...
> I don't know if I'm saying this right but is it possible to pass a
> variable into a variable in matlab?
> For example in ...
VARIABLE (was is VARIABLE does ? )
Charles Melice raises an interesting question when he asks why VARIABLE
is in the CORE wordset. Andrew Haley responded that CORE is not intended
to be a minimalist wordset.
We have in the past had some discussion re: proper selection of a minimal
set of words. Does anyone think there is merit to the suggestion of adding
a minimal-CORE wordset to the revised Standard (whenever that happens)?
The virtue of a Standard minimal word set would be the virtue we have
(albeit with some exceptions) found in having a Standard Forth, namely
virtually painless portability and inter-operability. I, for o...
A variables variableshow can I declare a variable with another variable name?
for example I will use PHP:
$a= "hello";
$a_hello="baybay";
print ${'a_'.$a) //output: baybay
how can i do it with no Arrays using python
thanks!
On Aug 23, 7:25=A0pm, Gandalf <goldn...@gmail.com> wrote:
> how can I declare a variable with another variable =A0name?
>
> for example =A0I will use PHP:
>
> $a=3D "hello";
>
> $a_hello=3D"baybay";
>
> print ${'a_'.$a) =A0//output: baybay
>
> how can i do it with no Arrays using =A0python...
Variable in variable?Hello,
I think that what I'm trying to do is impossible, but before I give up I
thought I'd try and pick a few more knowledgeable brains than my own.
I have any array of user defined type variables. I need to loop through the
array (doing certain calculations) on a particular member variable. I then
want to loop through the array again on a different member variable doing
very similar calculations. I only need to change a couple things in the
loop, otherwise the loop is identical from one member to the other. In a
nutshell, what I'm trying to do is use a variable, that will c...
Variable in a variableHi, I would like to print a variable into a variable for ex.
n = 1;
x=[('frame'),n,('.png')];
Result : frame.png expected: frame1.png
Is there anyway i could do this by any method.
Awaiting for your reply
"Bejoy Thomas" <bejoy.thomas@yahoo.in> wrote in message
news:h4k998$2cj$1@fred.mathworks.com...
> Hi, I would like to print a variable into a variable for ex.
>
> n = 1;
> x=[('frame'),n,('.png')];
>
> Result : frame.png expected: frame1.png
>
> Is there anyway i could do this by any method.
Use SPRINTF or NUM2S...
Variable VariablesI came across the interesting notion of $a and $$a, which in turns uses
the string in $a as a $-suffix to make a new dynamic variable.
Can someone illustrate a practical use out of it? I will be very curious
to see one (webdesign related) example of its usage.
Thanks,
Animesh
..oO(Animesh K)
>I came across the interesting notion of $a and $$a, which in turns uses
>the string in $a as a $-suffix to make a new dynamic variable.
>
>Can someone illustrate a practical use out of it? I will be very curious
>to see one (webdesign related) example of its usage.
There's hardly a reason to use them. Often enough they are misused in
situations where an array would be much more appropriate.
Micha
Animesh K wrote:
> I came across the interesting notion of $a and $$a, which in turns uses
> the string in $a as a $-suffix to make a new dynamic variable.
>
> Can someone illustrate a practical use out of it? I will be very curious
> to see one (webdesign related) example of its usage.
>
> Thanks,
> Animesh
>
I agree with Micha. Variable variables are a solution looking for a
problem. It creates code which is very difficult to manage and update,
and should not be used.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Jerry Stuckle wrote:
> Animesh K wrote:
>> I came across the interesting notion of $a and $$a, wh...
Variable VariableHi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc:
i = anyclass()
a.shutdown()
b.update()
Any Ideas?
Many Thanks, m
Tanteauguri wrote:
> Hi List, is there in python a variable variable like in PHP ($$var)?
>
> What I want to do is something like that:
>
> pc=["a","b","c"]
>
> for i in pc:
> i = anyclass()
>
> a.shutdown()
> b.update()
Use a dictionary:
stuff = {}
pc = ['a', 'b', ...
Assign variables to a new variable based on variable names in SASThank so much Nagakumar Sridhar and Fehd, Ronald J. for answering my
previous
question. However I was not clear in the original post. I modified my
phrasing
and the new version is below:
I have met the following problem and I need your expert help.
The variable names in the data set looks like this:
a_1995q3 a_1995q4 a_1997q1 ........... a_2003q4 n
Please note that "quarter" numbers in "a_****q*" variables may not be
continuous, i.e. there might be a missing quarter.
and n can have the value of any quarter for while a_quarter exists,
say
"1995q3", "...
Re: Combine several variables to one variable (variable name +On Mon, 8 May 2006 09:03:37 +0100, Deng, Yue <Yue.Deng@ASTRAZENECA.COM>
wrote:
>Dear all,
>
>I have a dataset as follows:
>
>V1 V2 V3 V4 V5....Vn
>1 A I a n.... t
>2 B II b y.... m
>3 C III c n.... t
>... .... .... ... ..... ...
>
>I would like to transfer the dataset as follows:
>
>V1 V2 VX
>1 A V3=I; V4=a; V5=n;....;Vn=t
>2 B V3=II; V4=b; V5=y;....;Vn=m
>3 C V3=III; V4=c; V5=n;....;Vn=t
>....
>
>How can I do it?
>
>Thanks,
>D
Hi D
The briefest demo ...