#!/usr/bin/perl use strict; use warnings; my %h = qw( a b c d ); func( \%h ); while ( my ( $key, $val ) = each %h ) { print "key is $key val is $val\n"; } sub func { my $incoming_hash_ref = shift; $incoming_hash_ref->{'e'} = 'f'; }
prints:
key is e val is f key is c val is d key is a val is b
IOW, the $_ isn't doing what you think it is doing (AFAICT).
Steve
In reply to Re: directly modify hash from subroutine
by stevieb
in thread directly modify hash from subroutine
by marksman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |