Re: How to pass the variable $Ip
- --- In perl-beginner@y..., Jorge Goncalvez <goncal11@c...> wrote:
> Hi, I wanted to pass $Ip to subnet but it didn't worked $Ip=1 in the functionThe line "my $Ip=@_;" is converting the array @_ into a scalar, when that happens, you get the count of elements in the array. The count of elements in this instance is 1. You need to assign scalar to scalar, or array to array.
> my code:
> sub get9xadressip()
> use Get9xRegIpAdress;
> my $Ip = Get9xRegIpAdress::GetIpAdress();
> sub subnet
> my $Ip=@_;
> push @IPREAL, $Ip;
> $Ip=~ s/(\d+\.\d+\.\d+)\.\d+/$1.0/;
> push @IP,$Ip;
my ($Ip) = @_; # This makes "($Ip)" an array for the assignment.
my $Ip = shift; # Shift will default to using @_.
# Note: shift will change @_
my $Ip = $_; # $_ is the scalar of the first element in @_.