Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
No such thing as a small change
 
PerlMonks  

How to compare two subroutine return values, to trigger email

by anakin30 (Acolyte)
on Sep 19, 2012 at 02:46 UTC ( #994398=perlquestion: print w/ replies, xml ) Need Help??
anakin30 has asked for the wisdom of the Perl Monks concerning the following question:

i have two subroutine, returning string type value.

and i print the return value using ampersand "&", example &DB_query1 and &DB_query2.

i need to compare these two string values, trigger an email notification if they are not equal, can i get some advice or reference or sample in here...

thanks....

Comment on How to compare two subroutine return values, to trigger email
Re: How to compare two subroutine return values, to trigger email
by GrandFather (Cardinal) on Sep 19, 2012 at 04:04 UTC

    First up, &DB_query1 probably isn't doing what you think. Use DB_query1() instead. Given that change as far as I can tell all you need do is:

    if (DB_query1() ne DB_query2()) { # Do stuff here if the strings don't match }
    True laziness is hard work

      Suppose the return result from subroutine query_LDAP and query_AD should be compared,but here the comparison not working.

      i have no idea what is wrong here, please advice dear monks..

      i have provided my source codes here, please assist..

      sub query_LDAP { $ldap = Net::LDAP->new( 'hostname' ); $mesg = $ldap->bind( 'uid=username,ou=xxxx,o=bbb', password => 'secret' ); $result = $ldap->modify( "uid=username,ou=xxxx,o=bbb", replace => {"name" => "star wars"} ); $result->code && warn "failed to add entry: ", $result->error ; $result = $ldap->search ( base => "ou=xxxx,o=bbb", filter => "uid=username" ) or die ("Failed on search.$!"); foreach my $entry ($result->entries) { my $LDAP_name= $entry->get_value( "name" ); print "Query Result from LDAP : ",$LDAP_name,"\n";} $mesg= $ldap->unbind;} # take down session sub query_AD { $ldap = Net::LDAP->new('hostname') or die "$0"; $mesg = $ldap->bind( 'cn=username,ou=somecontainer,DC=com', password => 'secret'); $result = $ldap->search(base => "ou=somecontainer,DC=com", filter=> "cn=username" ) or die ("Failed on search.$!"); foreach my $entry ($result->entries){ my $AD_name= $entry->get_value( "name" ); print "Query Result from AD : ",$AD_name,"\n";} $mesg= $ldap->unbind;} # take down session if (query_LDAP() ne query_AD()) { print "not identical!!!!\n";} else{ print "its the same\n";}
        Hi anakin30,

        I believe GrandFather was under the impression that your query_LDAP and query_AD functions would return the results of the queries, instead of printing them to the screen.

        If you return $LDAP_name; and return $AD_name; at the end of each function, your comparison should do what you want.

Re: How to compare two subroutine return values, to trigger email
by cheekuperl (Monk) on Sep 19, 2012 at 04:06 UTC

      Perhaps a more direct link would be to Equality Operators (the string comparison operators are at the end of the section) in perlop.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994398]
Approved by Jim
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-04-19 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls