Loading ...
Sorry, an error occurred while loading the content.

Re: How to pass the variable $Ip

Expand Messages
  • b_harnish
    ... The 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
    Message 1 of 2 , Mar 7, 2002
    • 0 Attachment
      --- 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 function
      > subnet;
      > Why?
      > my code:
      > sub get9xadressip()
      > {
      > use Get9xRegIpAdress;
      > my $Ip = Get9xRegIpAdress::GetIpAdress();
      > &subnet($Ip);
      >
      > }
      >
      > sub subnet
      > {
      > my $Ip=@_;
      > push @IPREAL, $Ip;
      > $Ip=~ s/(\d+\.\d+\.\d+)\.\d+/$1.0/;
      > push @IP,$Ip;
      >
      > }
      >
      > &get9xadressip();
      >
      > Thanks.

      The 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 ($Ip) = @_; # This makes "($Ip)" an array for the assignment.
      or
      my $Ip = shift; # Shift will default to using @_.
      # Note: shift will change @_
      or
      my $Ip = $_[0]; # $_[0] is the scalar of the first element in @_.

      - Brian
    Your message has been successfully submitted and would be delivered to recipients shortly.