Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: regex in perl

by user786 (Sexton)
on Jun 15, 2016 at 03:40 UTC ( [id://1165680]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^5: regex in perl
by afoken (Chancellor) on Jun 15, 2016 at 05:58 UTC
    "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". ;-)
Re^5: regex in perl
by Anonymous Monk on Jun 15, 2016 at 03:44 UTC
    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
Re^5: regex in perl
by stevieb (Canon) on Jun 15, 2016 at 12:24 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1165680]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-23 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found