A
A. Farber
Hi,
I have a hash where keys and values are file paths.
I'm going to use that hash to generate a GNU Makefile.
For some parts of the file paths I have shortcuts
(like $(TOPDIR)) which I'd like to substitute into the
paths. I.e. I'd like to go through the hash keys and
perform a substitution on them, like in this test case:
perl -e '%h=(a=>1,b=>2); for (keys %h) { s/a/b/ }; print keys %h'
ab
The code above doesn't work as expected - I'd need it to
print "bb" and not "ab". Looks like the hash keys aren't
the "lvalue" described in the "perldoc perlsyn":
If any element of LIST is an lvalue, you can modify it by
modifying VAR inside the loop. Conversely, if any element
of LIST is NOT an lvalue, any attempt to modify that ele-
ment will fail. In other words, the "foreach" loop index
variable is an implicit alias for each item in the list
that you're looping over.
What could I do to solve this problem, please?
I'd prefer a solution with for() or while() because
I need to perform few more operations on the hash keys.
Regards
Alex
I have a hash where keys and values are file paths.
I'm going to use that hash to generate a GNU Makefile.
For some parts of the file paths I have shortcuts
(like $(TOPDIR)) which I'd like to substitute into the
paths. I.e. I'd like to go through the hash keys and
perform a substitution on them, like in this test case:
perl -e '%h=(a=>1,b=>2); for (keys %h) { s/a/b/ }; print keys %h'
ab
The code above doesn't work as expected - I'd need it to
print "bb" and not "ab". Looks like the hash keys aren't
the "lvalue" described in the "perldoc perlsyn":
If any element of LIST is an lvalue, you can modify it by
modifying VAR inside the loop. Conversely, if any element
of LIST is NOT an lvalue, any attempt to modify that ele-
ment will fail. In other words, the "foreach" loop index
variable is an implicit alias for each item in the list
that you're looping over.
What could I do to solve this problem, please?
I'd prefer a solution with for() or while() because
I need to perform few more operations on the hash keys.
Regards
Alex