Dearest perl Monks, I wrote this simple subroutine in order to add users to a small network program to which I needed to add authentication . When I call the subroutine, the user enters both username and password , the password is encrypted, and the script prints the combination.Or, that is what is SUPPOSED to happen; The problem is that the entire combination string ,stored in $out,does not print. As it is below it prints ".:encryptedpassword" instead of "username:encryptedpassword" .If I set $out to $username only it just prints the username. if I set $out to $username\n, it prints $username MINUS the first two chars.. I have tried turning off line buffering on the output filehandle, PASSWD, and this does not appear to be the problem. The code is below, any help would be appreciated, thanks :
sub adduser{ $passwd = shift; my ($out,$pw); my @salt = ("A".."Z","a".."z","0".."9","/",",","."); USER:{ print CLIENT "New UserName:"; my $username=<CLIENT>; if ($username =~ /\S+/){ chomp $username;} else{goto USER; } $out = "$username" ; } PASS:{ print CLIENT "New User Password:"; my $password=<CLIENT>; if ($password =~ /\S+/){ chomp $password;} else{goto USER; } my $salt = $salt[rand @salt].$salt[rand @salt]; my $pw = crypt($password,$salt); $out = "$out:$pw\n"; } open PASSWD, ">> $passwd" || die" problem appending to $passwd :$! \n"; print PASSWD "$out"; close PASSWD; }

In reply to print() wierdness by singsing

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.