Phoenix.pm: Please help, my brain is fried
Kevin Buettner
kev at primenet.com
Wed Jan 26 20:18:30 CST 2000
On Jan 26, 7:04pm, Shay Harding wrote:
> OK, I have the code below, and can't figure out why it is misbehaving and I am
> figuring it is something simple but due to working 80+ hours a week, I can't
> see it. This is really not part of any program, just something I was messing
> with. It basically creates a variable length string (6-12 alphanumeric
> characters), except the string returned is not alphanumeric.
>
>
> #!/usr/bin/perl5
>
> my $count = 0;
> print "\n\n", create_login_id(), "\n";
>
>
>
> sub create_login_id(){
> srand;
> my $temp = '';
>
> my $length = int(rand(6))+6;
>
> for (my $x = 1; $x <= $length; $x++){
> my $t = get_char();
> $temp .= chr($t)."($t)";
> }
>
> return $temp;
> }
>
>
> sub get_char(){
> srand;
> $count++;
>
> my $char = int(rand(57))+65;
> print $count, " ", chr($char), "\n";
>
> get_char() if ($char >= 91 && $char <= 96);
> return $char;
> }
>
>
>
> Sample output is:
>
>
> This is the loops through the routine 'get_char'
>
> 1 C
> 2 p
> 3 p
> 4 ]
> 5 W
> 6 [
> 7 M
> 8 x
> 9 b
>
>
> Here when it hits loop 4 it should do another loop since I exclude ASCII 93,
> and it does this except below as you can see it keeps ASCII 93 and doesn't use
> loop 5 value which would be valid. Using the 'my' scoping the number 4 value
> should go out of scope on the recursive call or am I missing something here?
>
>
> C(67)p(112)p(112)](93)[(91)x(120)b(98)
You might try changing
get_char() if ($char >= 91 && $char <= 96);
to
$char = get_char() if ($char >= 91 && $char <= 96);
Kevin
--
Kevin Buettner
kev at primenet.com, kevinb at redhat.com
More information about the Phoenix-pm
mailing list