dear monks,
i have a problem while retrieving the size of an array of hash passed as an argument of a sub.
Please consider the following code.
#!/usr/bin/perl -w
use strict;
sub rien2rien (@)
{
my @other = shift;
for (my $i = 0; $i < @other; $i++)
{
my $a = $other[$i]{'first'};
my $b = $other[$i]{'second'};
print "in other sub:\t$a\t$b\n";
}
}
sub rien ()
{
my $i = 0;
my $file ="somefile.html";
my $regexp = "(.*)something(.*)";
open(FH, "<$file");
my @rrayOfHash;
(my @data) = split(/<br>/, <FH>);
foreach my $tuff (@data)
{
if ($tuff =~ /$regexp/)
{
$rrayOfHash[$i]{'first'} = $1;
$rrayOfHash[$i]{'second'} =$2;
$i++;
}
}
for ($i = 0 ;$i <@data; $i++)
{
my $a = $rrayOfHash[$i]{'first'};
my $b = $rrayOfHash[$i]{'second'};
print "in sub: \t$a\t$b\n";
}
return @rrayOfHash;
}
my @ut = &rien();
for (my $i = 0; $i < @ut; $i++)
{
my $a = $ut[$i]{'first'};
my $b = $ut[$i]{'second'};
print "in main:\t$a\t$b\n";
}
&rien2rien(@ut);
the code produce this output :
in sub: bla bleu
in sub: bli blo
in main: bla bleu
in main: bli blo
in other sub: bla bleu
i imagine it may be a context question but i can't manage how to retrieve the whole array in the "other sub".
Thanks in advance for your help
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.