I want to return two hashes from a subroutine
does not seem to work and gives this output
Use of uninitialized value in concatenation (.) or string at C:\scripts\perl\source\testhash.pl line 20.
test1 0 type-test2-0 value1-test2-0value1-test2-0
test1 1 type-test2-1 value1-test2-1value1-test2-1
test1 2 type-test2-2 value1-test2-2value1-test2-2
test1 3 type-test2-3 value1-test2-3value1-test2-3
test1 4 type-test2-4 value1-test2-4value1-test2-4
test1 5 type-test2-5 value1-test2-5value1-test2-5
test1 6 type-test2-6 value1-test2-6value1-test2-6
test1 7 type-test2-7 value1-test2-7value1-test2-7
Use of uninitialized value in concatenation (.) or string
at C:\scripts\perl\source\testhash.pl line 20.
Use of uninitialized value in concatenation (.) or string
at C:\scripts\perl\source\testhash.pl line 20.
Use of uninitialized value in concatenation (.) or string
at C:\scripts\perl\source\testhash.pl line 20.
Use of uninitialized value in concatenation (.) or string
at C:\scripts\perl\source\testhash.pl line 20.
what is wrong in my code
#!/usr/bin/perl -w
use strict;
my %test1;
my %test2;
my $k;
(%test1,%test2) = &testsub;
foreach $k (sort keys %test1) {
print " test1 $k $test1{$k}{'type'} $test1{$k}{'value1'}$test1{$k}{'v
+alue1'} \n";
}
foreach $k (sort keys %test2) {
print " test1 $k $test2{$k}{'type'} $test2{$k}{'value1'}$test2{$k}{'v
+alue1'} \n";
}
sub testsub {
my $hasrows=0;
my %test1;
my %test2;
while ($hasrows < 5) {
$test1{$hasrows} = {
'type' => "type-test-$1hasrows",
'value1' => "value1-test1-$hasrows",
'value2' => "value2-test1-$hasrows"
};
$hasrows +=1;
}
$hasrows=0;
while ($hasrows < 8) {
$test2{$hasrows} = {
'type' => "type-test2-$hasrows",
'value1' => "value1-test2-$hasrows",
'value2' => "value2-test2-$hasrows"
};
$hasrows +=1;
}
return (%test1,%test2);
}
thks for your help
HarryC >/br>
20071029 Janitored by Corion: Changed </br> tags to <br/> tags, as per Writeup Formatting Tips
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.