Hello. This is my secound day learning perl. So I thought I would write a simple script to use an array and randomly choose one of the 26 availible letters which will be checked against what you wanted to find, then print how many times it took.
here is what I have to find one letter of your choosing.
Code:
#!/usr/bin/perl
@array=('A' .. 'Z' );
$times = 0;
while ($hold ne "A") {
$randnum = int( rand(26) );
$hold = @array[$randnum];
$times++;
}
print("We found A! Tt took $times times \n");
Cool. This works fine for what I want. Now here is my question: How can I get this same model to work for a string of more then 1 letters.
For example, locating a string that is 2 letters, such as AB or ABC. Like maybe I would like to see how long it takes to randomly find my name 'JOHN'. Hope I provided enough info about how goal.