I am trying to write a perl script to generate random names ed. ( Qrhfh, Jdfhdh, Dfkjns) etc.
So the script should ask me the number of random names and when I give say 4, It should give me four random names and then it should insert these names into the sql database to a table which is already created.
Here is my code.
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- my $name;
- my @charset = (('A'..'Z'), ('a'..'z'));
- my $range = $#charset + 1;
- print "Enter the limit\n";
- $lim = <STDIN>;
- until ($lim == 0){
- for (1..8) {
- $name .= $charset[int(rand($range))];
- }
- print "$name\n";
- $lim = $lim - 1;
- }
say when I run this script and enter 6
It gives me the following weird output.
wFposZwA
wFposZwAHnAEHiei
wFposZwAHnAEHieiJLNQZiTW
wFposZwAHnAEHieiJLNQZiTWzxOUiiru
wFposZwAHnAEHieiJLNQZiTWzxOUiiruHdinQLkp
wFposZwAHnAEHieiJLNQZiTWzxOUiiruHdinQLkpdLwNtOYW
I dont want it to have same prefix in the front and secondly I don't want its length to increase.
Anyone got a clue wats happening ?