My example code gives me the following:
The content of file2 is:
ARRAY(0x1fd55b0)
The content of file1 is:
ARRAY(0x1fb5a68)
The content of file3 is:
ARRAY(0x1fd56d0)
Inside the sub I want to dereference the content of that ARRAY but even after reading a lot of other examples and trying out many solutions I did not find the right way to do it on my own... (instead of the 'ARRAY' it should show all values in there like host1, bla etc.)
Also I want to be able to dynamically extend my orginal %hash with a new file-entry ($key) named file4 with its own values ($insert_val) in this example, I also had problems with that part (which is commented out atm).
I hope anyone can help me...
Many thanks in advance!
sub testfunc (\%)
{
my ( $href ) = @_;
my $key = "file4";
my $insert_val="host1";
my $insert_val2="foo";
#push(@{$href{$key}}, $insert_val);
#push(@{$href{$key}}, $insert_val2);
foreach my $file (keys %$href) {
print "The content of $file is:\n";
foreach my $line ( $href->{$file} ) {
print "\t$line\n";
}
}
}
my %hash = ( file1 => [ 'host1', 'bla', 'foo', ], file2 => [ 'host2',
+'host1', '..', ], file3 => [ 'x', 'host2', 'host1' ] );
testfunc(%hash);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.