samedi 12 mars 2022

Why does this show a random number to the screen but write a different number to a file using the same variable $userid?

sub writeuserid {


$dir = "./tmp/userhome/$username/";

mkdir($dir, 0755);

$dirpath = "./tmp/userhome/$username/userid";


$char0 = int(rand(10));
$char1 = int(rand(10));
$char2 = int(rand(10));
$char3 = int(rand(10));
$char4 = int(rand(10));
$char5 = int(rand(10));
$char6 = int(rand(10));
$char7 = int(rand(10));


my $userid = 
$char0 . '' . 
$char1 . '' . 
$char2 . '' . 
$char3 . '' . 
$char4 . '' . 
$char5 . '' . 
$char6 . '' . 
$char7;

#this prints the new random number correctly to screen

print $userid;

#this prints a different number to the file and keeps printing only the wrong/different number to all new users giving them all the same unique id

open(FH, '>', $dirpath);

print FH $userid;

close(FH);

#and this writes the new number to the screen

print $userid;


die print "user files written";

}




Aucun commentaire:

Enregistrer un commentaire