I am hacking a git-svn Perl script. I have a $paths
variable which I think contains an array of individual paths, but I am having a hard time iterating over it. My end goal is to to add an additional attribute to one path.
Here is the dumper output.
{
"/dira" => {
action => "A",
copyfrom_path => undef,
copyfrom_rev => -1
},
"/dira/dirb" => {
action => "A",
copyfrom_path => undef,
copyfrom_rev => -1
},
"/dira/dirb/test.55mb.file" => {
action => "A",
copyfrom_path => undef,
copyfrom_rev => -1
},
}
According to that output, $paths
is a reference to a hash of references to hashes.
If you know which path you want to extend, you don't need to iterate:
$paths->{'/foo/bar'}{'my_attribute'} = 42;
If you want to do this uniformly to all paths, you can do this:
for my $attrs (values %$paths) {
$attrs->{'my_attribute'} = 42;
}
See perldoc perldata
for information about hashes and perldoc perlreftut
for references and nested data structures.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.