Am passing one array and one scalar to a function to check where that value is part of array or not in case it is not part then push to array. For reference purpose what It has to display is while pushing it has to display the name of array . Here is my code
use v5.10.1;
use strict;
use warnings;
my @ARRAY1 = qw/This is array of backup /;
my @ARRAY2;
my $value = "version.xml" ;
sub CheckPush($$)
{
my $val = shift (@_);
my $array_ref= shift (@_);
unless ($val ~~ @$array_ref )
{
print "$val is going to push to array \n";
push(@$array_ref,$val);
}
return (@$array_ref);
}
@ARRAY1 = CheckPush($value,\@ARRAY1);
print "out \n";
foreach $_ (@ARRAY1) {
print "$_ \n";
}
@ARRAY2 = CheckPush ($value,\@ARRAY2);
print "out2 \n";
foreach $_ (@ARRAY2) {
print "$_ \n";
}
Out put should be like below
$val is going to push Array (@ARRAY1)
$val is going to push Array (@ARRAY2)
Pass the name of the array along with the reference; it isn't that hard.
People do do things like this with source filters or PadWalker::var_name, but it isn't a good idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With