in reply to Re: If condition
in thread If condition

If I use this way on the loop, all the values will be null

Replies are listed 'Best First'.
Re^3: If condition
by jeanluca (Deacon) on Jul 14, 2009 at 11:48 UTC
    you should do something like
    my $cor ; my $date ; for my $data_pair (@data_list) { if($data_pair->{'key'} eq 'correct'){ $cor= $data_pair->{'value'}; } if($data_pair->{'key'} eq 'date'){ $date= $data_pair->{'value'}; } $sql_content .= "INSERT IGNORE INTO correct SET text='".$cor."', + date='".$date."'; }
    I'm not sure if this is what you want, but it makes more sense to me!
    And as mentioned already, use placeholders!!

    UPDATE: Hmmm, this doesn't make much sense too :) but I hope it helps!
      It will make more sense if you move assignment to $sql_content out of loop. You probably want something like
      my $cor ; my $date ; for my $data_pair (@data_list) { if($data_pair->{'key'} eq 'correct'){ $cor= $data_pair->{'value'}; } if($data_pair->{'key'} eq 'date'){ $date= $data_pair->{'value'}; } } my $sql_content = "INSERT IGNORE INTO correct SET text='".$cor."' date +='" .$date."'";
      If this is what we are looking for than try this as well
      my %data_hash = map {$_->{'key'} => $_->{'value'} if ($_->{'key'} eq ' +correct' || $_->{'key'} eq 'date')} @data_list; my $sql_content = "\nINSERT IGNORE INTO correct SET text='".$data_hash +{'correct'}."' date='" .$data_hash{'date'}."'";
      Regards,
      Ashish