CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Save result, not print?

 



rainbowz
Deleted

May 20, 2001, 12:06 PM

Post #1 of 2 (569 views)
Save result, not print? Can't Post

Hi,

Here's a small part of a script I'm putting together (extra green newbie) and I can't figure out how to do this really simple thing: this script I got from a book (Perl for Dummies, pp. 309) generates a semi-readable password - works grgeat, in fact. However, it wants to print the resulting password to the screen while I want to save the password to $pw to be included in an e-mail and add it to a flatfile DB. How do I "save" this password?? It's probably incredibly simple... but it escapes me and I've been looking through lots of books to see what I can use other than
"{print $c..." in that 2nd-last line.


####################################
#!/usr/bin/perl

pass_gen();

sub pass_gen
{
$SeenNo = int(rand(100)) + 1;
srand($SeedNo ^ time);

@c=split(/ */, "bcdfghjlmnprstvwxyz");
@v=split(/ */, "aeiou");

for ($i =1; $i <=4; $i += 1) {print $c[int(rand(20))], $v[int(rand(5))] }
}
####################################

Thanks for any guidance here!



Mortimer
journeyman

May 21, 2001, 12:59 AM

Post #2 of 2 (558 views)
Re: Save result, not print? [In reply to] Can't Post

You could concatanate the returned calculations on each run through the loop...


Code
&pass_gen; 

print "< br >";
print $password;

sub pass_gen{
$SeenNo = int( rand(100) ) + 1;
srand($SeedNo ^ time);

@c = split(/ */, "bcdfghjlmnprstvwxyz");
@v = split(/ */, "aeiou");

for($i =1; $i <=4; $i += 1){
$con = $c[int(rand(20))];
$vow = $v[int(rand(5))];
$password .= "$con$vow";
print "$con$vow";
}
}

I've adjusted the layout of the code to prove that the return value of the function is the same as what you'de eventually print to your data file.
Don't rely on this code for length consistency. It misses characters sometimes. Also, the first few runs returned a string with the same character at the beginning, but thereafter, didn't.

Hope this helps.

Dave.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives