May I suggest that you get your terminology straightened out first? It
makes communication so much easier if everyone uses the same terms for
the same things.

There are hashes: they are mappings from strings to scalars. In the old
days they were also called associative arrays.
There are arrays: they are mappings from (consecutive whole) numbers to
scalars.
There are variables: they can be any of scalar, array, hash, and a few
other types.
And there are values: they are typically stored in variables.

Now, having said that, there are no arrays of variables.
>Later on, I want loop through these array and modify the value and set
>back to the variable.
>
>do a loop now
>get variable back
>change value
>
>$path1 = 'c:\newpath';
>$filea = 'Y:\newfilea.txt';
>$namex = 'Dr. Y';
>
>How can I achieve something like this? Thanks.

Advertisements

I want to reference the variables and change the value to that
reference variable.

On Apr 24, 4:29 pm, Jürgen Exner <> wrote:
> Slickuser <> wrote:
> >I have these variables:
> >my $path1 = 'c:\abc';
> >my $filea = 'Y:\a.txt';
> >my $namex = 'Dr. X';
>
> >I want to push this into a hash array or array of variables & values.
>
> May I suggest that you get your terminology straightened out first? It
> makes communication so much easier if everyone uses the same terms for
> the same things.
>
> There are hashes: they are mappings from strings to scalars. In the old
> days they were also called associative arrays.
> There are arrays: they are mappings from (consecutive whole) numbers to
> scalars.
> There are variables: they can be any of scalar, array, hash, and a few
> other types.
> And there are values: they are typically stored in variables.
>
> Now, having said that, there are no arrays of variables.
>
> >Later on, I want loop through these array and modify the value and set
> >back to the variable.
>
> >do a loop now
> >get variable back
> >change value
>
> >$path1 = 'c:\newpath';
> >$filea = 'Y:\newfilea.txt';
> >$namex = 'Dr. Y';
>
> >How can I achieve something like this? Thanks.
>
> Wild guess: maybe you are looking for a simple hash?
> %myhash = (path1 => 'c:\newpath',
> filea => 'Y:\newfilea.txt',
> namex => 'Dr. Y};
>
> You can loop through the entries by
> foreach (keys(%myhash) {
> print $myhash{$_};
> }
> And of course you can assign and modify the values as you please, too.
>
> Or are you looking for references, i.e. you want to store a reference to
> each of your variables in such a hash or an array and then work with
> those references?
>
> jue

[Re-ordered into standard reading order]
Slickuser <> wrote:
>On Apr 24, 4:29 pm, Jürgen Exner <> wrote:
>> Slickuser <> wrote:
>> >I have these variables:
>> >my $path1 = 'c:\abc';
>> >my $filea = 'Y:\a.txt';
>> >my $namex = 'Dr. X';
>>
>> >I want to push this into a hash array or array of variables & values.
>>
>> May I suggest that you get your terminology straightened out first? It
>> makes communication so much easier if everyone uses the same terms for
>> the same things.
[...]
>> Or are you looking for references, i.e. you want to store a reference to
>> each of your variables in such a hash or an array and then work with
>> those references?
>I want to reference the variables and change the value to that
>reference variable.

The top will assign by manually by the user, but the bottom one will
somehow automate re-assign the value. I don't want to do one by one.
That's why I'm thinking of putting in a hash and loop and modify the
value. This is where I'm stuck.

Mostly I just do a replace and search but I don't know which variable
to set it back to.

How would I achieve this in a loop?
$HASHX{'path1'} = $path1;
$HASHX{'filea '} = $filea;

[Re-ordered AGAIN into standard reading order]
[Please do not top post]
Slickuser <> wrote:
>On Apr 24, 6:20 pm, Jürgen Exner <> wrote:
>> [Re-ordered into standard reading order]
>> Slickuser <> wrote:
>> >On Apr 24, 4:29 pm, Jürgen Exner <> wrote:
>> >> Slickuser <> wrote:
>> >> >I have these variables:
>> >> >my $path1 = 'c:\abc';
>> >> >my $filea = 'Y:\a.txt';
>> >> >my $namex = 'Dr. X';
>>
>> >> >I want to push this into a hash array or array of variables & values.
>>
>> >> May I suggest that you get your terminology straightened out first? It
>> >> makes communication so much easier if everyone uses the same terms for
>> >> the same things.
>> [...]
>> >> Or are you looking for references, i.e. you want to store a reference to
>> >> each of your variables in such a hash or an array and then work with
>> >> those references?
>> >I want to reference the variables and change the value to that
>> >reference variable.
>>
>> Then please see "perldoc perlreftut" and "perldoc perlref".
>>
>> jue
>my $path1 = 'c:\abc';
>my $filea = 'Y:\a.txt';
>my $namex = 'Dr. X';
>
>My goal is get from the top the end.
>
>$path1 = 'c:\newpath';
>$filea = 'Y:\newfilea.txt';
>$namex = 'Dr. Y';
>
>
>The top will assign by manually by the user, but the bottom one will
>somehow automate re-assign the value. I don't want to do one by one.
>That's why I'm thinking of putting in a hash and loop and modify the
>value. This is where I'm stuck.

Sorry, my EPS:SI capabilities are very limited and I am very poor at
guessing what other people might have meant.
Someone else will have to decode the paragraph above and translate it
into plain English. I have no idea what you mean by that.
>Mostly I just do a replace and search but I don't know which variable
>to set it back to.
>
>How would I achieve this in a loop?
>$HASHX{'path1'} = $path1;
>$HASHX{'filea '} = $filea;

I don't get it. Are you looking for references are you looking for loops
or what? One day you are saying X and the next day you are saying Y. I
am lost and am giving up now.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!