473,513 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with the code?

24 New Member
Expand|Select|Wrap|Line Numbers
  1. my $mesg2 = $ldap->modify('$dn', replace =>{'userpassword'=> 'Test123' });
  2.  
  3.  
  4.         my $error = $mesg2->error;
  5.         print "\n############$dn \n############$error";
  6.         if($error == "Success")
  7.         {
  8.             print "\nPassword $error fully Changed";
  9.         }
  10.         else
  11.         {
  12.             print "\nCaught an exception: $error";
  13.         }
  14.     }
  15.     print "\n\n***************END OF OPERATION***************\n\n"
  16.  
  17. }
  18.  
  19. $ldap->unbind;
  20.  
  21. out put of line 5:
  22. ############uid=dphdlmk,ou=people,ou=associates,dc=albertsons,dc=com
  23. ############Invalid DN
  24.  
  25.  

After successfully binding the code with the LDAP server, I tried to run this code to change the password of the user in the LDAP server.

The problem is i that didn't know weather the password has been changed or not. To check this i have introduced a
if-else block. The flow of control is managed by the value of error variable, which should show "Success" in idle case. But when i print its value (see line 5), it shows the above stated output (see line 21).

Concern:
If we go with the output, then how is it possible that for a valid DN (as shown in line 22), the error variable is showing Invalid DN.

Secondly, Since the value of error variable is "Invalid DN" control should go to the else block, but it is going in the If block.

thanks in advance.
Jan 5 '11 #1
6 1653
RonB
589 Recognized Expert Moderator Contributor
== is a numerical test, it does not compare strings.

Change it to eq.
Expand|Select|Wrap|Line Numbers
  1. if($error eq "Success")
Jan 5 '11 #2
tyagithehacker
24 New Member
Expand|Select|Wrap|Line Numbers
  1. if ($ent ==  "")
  2.     {
  3.         print "\nNo Match Found !!!\nPassword Cannot be changed";
  4.     }
  5.     else
  6.     {    
  7.         my $dn=$ent->get_value('entrydn');
  8.         my $cn=$ent->get_value('cn');
  9.         print"\nOne Match Found !!!\nEmployee Name: $cn";
  10.  
  11.         my $mesg2 = $ldap->modify('$dn', replace =>{'userpassword'=> 'Test123' });
  12.  
  13.         my $error = $mesg2->error;
  14.         print "\n############$dn \n############$error";
  15.  
  16.         if($error == "Success")
  17.         {
  18.             print "\nPassword $error fully Changed";
  19.         }
  20.         else
  21.         {
  22.             print "\nCaught an exception: $error";
  23.         }
  24.     }
  25.     print "\n\n***************END OF OPERATION***************\n\n"
  26.  
Thanks for replying, RonB.I tried what u said, it worked for line 16.
But still i don't see this as an exact reason. As if it were true, then expression at line one also follow the same rule. If i compare that expression using '==' operator it always return false (ie. go to else part). irrespective of rvalue is string(i tried "" , " " and "anystring") or integer (i tried -1,0 and 1).


Moreover, do you have any idea about my first concern(from previous post) ?
If we go with the output, then how is it possible that for a valid DN (as shown in line 22), the error variable is showing Invalid DN.
Jan 5 '11 #3
bazz
3 New Member
if you are comparing a variable to a sting, you should use 'eq' as already said. if comparing integers use '==' and if coparing against a null or empty value, I would use 'eq'

(Ignore the '' surrounding the operators).

bazz
Jan 5 '11 #4
RonB
589 Recognized Expert Moderator Contributor
Hi Bazz,

I see you're branching out.

Ron aka FishMonger
Jan 5 '11 #5
RonB
589 Recognized Expert Moderator Contributor
Expand|Select|Wrap|Line Numbers
  1. my $mesg2 = $ldap->modify('$dn', replace =>{'userpassword'=> 'Test123' });
Don't quote individual vars.

Since you're using single quotes around the $dn var, perl won't interpolate it. Instead, it sees it as the literal string $dn which is why you received the error message.
Jan 5 '11 #6
tyagithehacker
24 New Member
What a damn silly blunder it was. Feeling offended now. Sorry guys.
Thanks Bazz
Thanks RonB
Jan 6 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3193
by: Lee Redeem | last post by:
Hi there I've created abd uploaded this basic PHP script: <html> <head> <title>PHP Test</title> </head> <body> <H1 align="center">
5
3662
by: Koen | last post by:
Hi all, I am experimenting with DAO. I wrote this sub to update one specific field of one specific row in one specific table. Nothing wrong with the SQL statement, but when I execute this I get...
3
2076
by: Jeff Cooper | last post by:
Hey Folks, I have a bunch of aspx pages in a solution. One of these pages, call it header1.aspx, has it's code behind in header1.aspx.vb. Another, header2.aspx, has header2.aspx.vb. When I...
8
1432
by: Polaris | last post by:
Hi Experts: The program creates Panels and inicilize them. When I run the code below, the program crashes (at the line commented below). Any help is appriciated. Thanks in Advance! Polaris ...
6
2731
by: Alvaro G. Vicario | last post by:
The code below inserts a <spantag around the image. It works fine in Firefox or Opera, but has a weird effect in Internet Explorer: browser keeps loading the image forever... Even though the...
8
2422
by: =?GB2312?B?yum09MXt?= | last post by:
today I forgot to include some header,then I found the error message by the compiler is quite strange. so I want to know exactly the inner details of the compiler impletation,if possible. and I...
3
2211
by: canabatz | last post by:
im using paging on this query: i got this code that returning wrong results: (SELECT bid_price, count(*) as n from bidding_details where bid_id=$bid_id GROUP BY bid_price DESC HAVING n = 1 ) ...
2
3158
by: doudou88 | last post by:
Hello, I try to debug a c# program using mono-debugger. But i need first to create .exe.mdb file, using the folowing command: gmcs -debug program.cs When doing this I get the following error:...
3
7314
by: muddasirmunir | last post by:
I am trying to give the following Icon in my form in vb6. http://www.mediafire.com/?ymzgkgyi50j But , when I put this in my form I got error "Invalid Picutre" What wrong in it? How to add...
0
7175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.