On Mon, Jan 28, 2002 at 02:35:10PM -0500, Nikola Janceski wrote: :Can the indented code below be written better (fewer lines or easier/better :algorithm)?
Yep. :srand(time ^ $$); # i don't care about the seed In recent versions of Perl (5.005* and up, I think), you don't need to call srand(). :$words = "Removes a random letter"; : :$randnum = int( rand( length($words) ) ); # always an interger number one :less than the length : : # this was the only way I could think of (without using an array) : $words =~ s/(.{$randnum})./$1/o; # to remove the random letter I prefer to use the substr() function. Here's what this would boil down to with it: substr $words, rand length $words, 1, ""; That's your entire program, right there. :-) To show you precedence, here it is with parens: substr( $words, rand( length( $words ) ), 1, ""; 'perldoc -f substr' for more info on it. Enjoy! Casey West -- "Windows NT 3.5 is not designed to route packets. . .so your Internet Service Provider cannot be a Windows NT 3.5 box." -- Microsoft, 1995, on Win NT RAS -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]