in reply to can i get the value outputed from my subroutine into my program as a value

Ray, a couple of points, they're below... I've assumed that phrase.txt only contains one line, tell me if I've got the wrong end ofthe stick...
#!D:\perl\bin -w use strict; use Win32::AdminMisc; #use Win32::AdminMisc qw(SetPassword); chomp(my $Server = <STDIN>); my $User = "Administrator"; my $Password = &getPassword; # ***********I've changed this line round - it doesn't # make sense the other way my $Result = Win32::AdminMisc::SetPassword( $Server, $User, $Password) + || die "Couldn't change password on $Server: $^E"; print $Result; sub getPassword { # use strict; #*************you don't need this line - you only have to 'use strict' + once per script use Crypt::Blowfish_PP; my $key="abcdefghijklmnopqrstuvwxyz123456789"; my $bf = Crypt::Blowfish_PP->new($key); open (IN,"phrase.txt") || die "Can't read phrase.txt: $!"; #*******this doesn't need to be a while loop if you're only expecting # one line my $encrypted_password = <IN>; #you probably want to close your file, as well close IN; my $decrypted_password = $bf->decrypt($encrypted_password); return $decrypted_password; # ************** you probably want to return this value, # i.e. make it the result of this subroutine, unless # I've completely misunderstood. Also, your there was a # typo in your variable name } #******** you no longer need a closing-curly to close the while loop, +but you do need one to close getPassword
Hope I've picked up the showstoppers, give that a go. It looks a bit hurried because I need to go and cook dinner!

andy.

  • Comment on Re: can i get the value outputed from my subroutine into my program as a value
  • Download Code

Replies are listed 'Best First'.
Re: Re: can i get the value outputed from my subroutine into my program as a value
by RayRay459 (Pilgrim) on Aug 15, 2001 at 21:41 UTC
    Thank you andye and everyone for your help. I really appreciate it. It does work. however i am getting an extra "1" at the end of the password. for example...$password gets assigned, after the decryption, "77ujump5" it becomes "77ujump51". ANy ideas why? thnx Ray I figured it out. I was having the script print the password on the console and also return a result(1 - success) :). Thanks to everyone for their help. Much Appreciated.