in reply to Re^2: generating unique filenames
in thread generating unique filenames
Hello Datz_cozee75,
Consider what the following assignments do:
my ($rvars) = shift; my %vars = %$rvars;
The first line shifts an argument off the call stack and copies it to the lexical variable $rvars. So far, so good. But then the second line dereferences $rvars as a hash (using the %{ ... } dereferencing syntax), and copies the contents of that hash into the new lexical hash variable %vars. From this point on, %vars is a local copy of what was in %$vars when the subroutine was called. Any changes made to %vars remain local to the subroutine, and have no effect on the contents of the original hash. So when next_file() is called, it receives $rvars as its first argument, but the hash to which that variable refers has no key named ref_alpha, so the attempt to access it on line 116 fails and produces the error message you are seeing.
But why do you want to make a copy of the hash %$rvars? Just remove the variable %vars, and access the “master hash” directly:
my ($rvars) = shift; ... my $path1 = $vars->{"to_images"}; my $path2 = $vars->{"to_magick"}; ...
Study perlreftut and get comfortable with Perl’s dereferencing syntax. It can be quite confusing at first, but if you persevere there will come a point where it will start to “click”, and then you’ll never look back!
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|