hello,
I've script like this;
In my script i want to put the sub in a .pm.
I've created a .pm with my sub and i call my sub in my script but i've an error that i don't understand.
This is my script :
This is my module:
This is the error:
I don't undestand why ??
Thanks
I've script like this;
In my script i want to put the sub in a .pm.
I've created a .pm with my sub and i call my sub in my script but i've an error that i don't understand.
This is my script :
Code:
#!/usr/bin/perl
use fonction;
my @tab = (
{
"name" => "Brian",
"age" => "25"
},
{
"name" => "tommy",
"age" => "29"
}
);
my %name;
foreach (@tab) {
$name{ $_->{'name'} } = $_;
}
sub fonc {
my @tablo = @_;
my $var;
foreach $var (@tablo) {
&fonction::test($var->{'name'});
print "$var->{'name'}=$var->{'age'}\n";
}
}
&fonc(@tab);
This is my module:
Code:
#!/usr/bin/perl
package fonction;
use warnings;
use strict;
use File::Basename;
use English;
sub test
{
my $varname = shift;
if ($name{"$varname"}{"age"} < 30 )
{
print "too young\n";
}
}
This is the error:
Global symbol "%name" requires explicit package name at fonction.pm line 20.
Compilation failed in require at C:\Documents and Settings\donny\Bureau\work\fonction.pl line 4.
BEGIN failed--compilation aborted at C:\Documents and Settings\donny\Bureau\work\fonction.pl line 4.
I don't undestand why ??
Thanks