Link to home
Start Free TrialLog in
Avatar of new_perl_user
new_perl_user

asked on

Comparing using hash in perl

Hi,

How to compare the below hash value to a character.

#!/share_nfs/perl/5.8.8/bin/perl

use strict;
use DBI();


my $db = DBI->connect( "dbi:Oracle:xxx", "xxx", "xxxx" )
    || die( $DBI::errstr . "\n" );

$db->{AutoCommit}    = 0;
$db->{RaiseError}    = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize}  = 16;


my $count;
my $SEL = $db->prepare("SELECT a.NUMBER,a.ID,  a.VOL 
FROM stage a
where a.status ='N'");

$SEL->execute();

while(my $subref = $SEL->fetchrow_hashref()) {
    my $batch_number=$subref->{'NUMBER'};
    my $nlm_unique_id=$subref->{'ID'};
    my $vol = $subref->{'VOL'};

print "$number | $vol \n";

if ($vol == {'S'}) 

{

print 'true';


}

else {

print 'false';


}


}

Open in new window

Avatar of FishMonger
FishMonger
Flag of United States of America image

if ($vol == {'S'})

Open in new window

== is the numerical comparison operator.

eq is the string comparison operator.

The correct syntax for that statement would then be:
if ($vol eq 'S')

Open in new window

Avatar of new_perl_user
new_perl_user

ASKER

Tries it is not working when it is not equal then printing true..
Then obviously you didn't adjust the code as I showed.

Please post your updated code which is not working as expected.
This worked for me..

If($vol =~ 's')

But need help  with invoking a script if condition satisifes. It is not invoking it..

#!/share_nfs/perl/5.8.8/bin/perl

use strict;
use DBI();


my $db = DBI->connect( "dbi:Oracle:xxx", "xxx", "xxxx" )
    || die( $DBI::errstr . "\n" );

$db->{AutoCommit}    = 0;
$db->{RaiseError}    = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize}  = 16;


my $count;
my $SEL = $db->prepare("SELECT a.NUMBER,a.ID,  a.VOL 
FROM stage a
where a.status ='N'");

$SEL->execute();

while(my $subref = $SEL->fetchrow_hashref()) {
    my $batch_number=$subref->{'NUMBER'};
    my $nlm_unique_id=$subref->{'ID'};
    my $vol = $subref->{'VOL'};

print "$number | $vol \n";

if ($vol =~ 'S') 

{

print 'true';

system('/usr/home/scripts/test.sh');

}

else {

print 'false';

system('/usr/home/scripts/test2.sh');

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial