On Sun, Jan 15, 2017 at 12:45:41PM -0800, [email protected] wrote:
> Hi
>
> On Sun, Jan 15, 2017, at 12:23 PM, Илья Рассадин wrote:
> > I think, you can use this aproach
>
> If I use either of those
>
>
> sub modrec {
> - my %args = %{ shift @_ };
> + my ($args) = @_;
>
> 30 my $fn = $args{FN};
> my $ar = $args{AR};
> my $ad = $args{AD};
> my @dr = @{$args{DR}};
>
> return;
> }
>
> or
>
> sub modrec {
> - my %args = %{ shift @_ };
> + my $args = shift @_;
>
> 30 my $fn = $args{FN};
> my $ar = $args{AR};
> my $ad = $args{AD};
> my @dr = @{$args{DR}};
>
> return;
> }
Naming multiple variables with the same name like you did ($args, %args) is a
bad idea. because when you want to access the value of the hash %args
($args{FN}) you are accessing in reality what was shifted in the scalar $args
and not the hash %args
because perl use simbolic reference.
here is a link that explain that
https://perlmaven.com/symbolic-reference-in-perl
>
> the script won't even execute. Both give the same error
>
> perl /home/aj/test.pl
> Global symbol "%args" requires explicit package name at
> /home/aj/test.pl line 30.
> Global symbol "%args" requires explicit package name at
> /home/aj/test.pl line 31.
> Global symbol "%args" requires explicit package name at
> /home/aj/test.pl line 32.
> Global symbol "%args" requires explicit package name at
> /home/aj/test.pl line 33.
> Execution of /home/aj/test.pl aborted due to compilation errors.
>
> Which is weird since after I make those changes I'm not even using "%args"
> anymore.
>
> AJ
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/