Greeting Dear Community.
I\'m trying to make a sub
in perl that takes a hash and a debug flag which defaults to zero. However I keep getting this error
You want to pass your hashes by value to your subroutine and this creates the problem. Try to pass your hash %h2
by reference instead (notice the \
before the %
):
&hash2print(\%h2, 1);
Then in your sub hash2print
, you can get the hash back in the following way:
sub hash2print {
(my $hashref, my $debug) = @_;
my %HoH = %$hashref; # dereference $hashref to get back the hash
...
You can read more about references here if you don't understand the concepts behind them.