in reply to If condition

this smells like a scoping problem. Did you use
use strict ; use warnings ;
at the beginning of you program. This is the idea
{ my $var = 10 ; } print "$var\n" ;
which doesn't print 10. But this does
my $var ; { $var = 10 ; } print "$var\n" ;
Hope this helps!

Replies are listed 'Best First'.
Re^2: If condition
by gem555 (Acolyte) on Jul 14, 2009 at 11:39 UTC
    If I use this way on the loop, all the values will be null
      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