in reply to Re: regex in perl
in thread regex in perl

This doesn't work

Replies are listed 'Best First'.
Re^3: regex in perl
by Anonymous Monk on Jun 15, 2016 at 03:27 UTC
    can you prove it? rewrite sub subroutine so it starts with  my $records = ...; # Data::Dumper output here
      sub subroutine { my ($self,$vip) = @_; my @ip = (); my $sql_query = $self->{queryObj}->execute( "select primary_ip from buddy_vips where machineIP=$vip"); my $records = $self->{queryObj}->result(); for my $row (@$records){ if (my ($ip) = $row->{machineIP} =~ /(\d+\.\d+\.\d+\.\d+)/){ $row->{machineIP} = $ip; } push @ip, $row->{machineIP}; } return \@ip; }
      output :

      Use of uninitialized value in pattern match (m//) at

      Use of uninitialized value in pattern match (m//) at

      Use of uninitialized value in pattern match (m//) at

        "select primary_ip from buddy_vips  where machineIP=$vip"
        $row->{machineIP} =~ /(\d+\.\d+\.\d+\.\d+)/

        How to you expect machineIP to magically appear in the result of the SELECT statement? You only select primary_ip.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Did you understand?  my $records = $self->{queryObj}->result() is not a data structure, it isn't output from Data::Dumper, it isn't something anybody except you can replicate -- there is no sense in trying to write code when we're guessing at the actual value of $records, without knowing the actual value of $records any code written to deal with it is a guess ie nonsense

        ummm... this is a lot different than your original code that I rewrote my working example to coincide with:

        sub subroutine { my ($self,$vip) = @_; my @ip = (); my $sql_query = $self->{queryObj}->execute( "select machineIP from 'tablename' where frontend=$vip"); my $records = $self->{queryObj}->result(); foreach my $row (@$records) { push @ip, $row->{machineIP}; } return \@ip; }

        As afoken stated above, the query you changed to doesn't even get the right column anymore, so it makes sense my code produces uninit warnings.