- Re: Regex problem extracting middle-word part of
> string
>
>
> > I didn't quite see why you would have to do a +1 on the following:
> >
> >my $RandomScript = $Scripts[int(rand($#Scripts + 1))];
>
> The '$#array' construct returns the in
> I didn't quite see why you would have to do a +1 on the following:
>
>my $RandomScript = $Scripts[int(rand($#Scripts + 1))];
The '$#array' construct returns the index of the last element of the
'@array'. 'rand $number' returns a random number between 0 (inclusive)
and $number (exclusive)
Thanks Janek and Japhy and Drieux for all the help on this!
I've yet to look at this Tie::Pick, but will.
In the meantime, I've gone with the Japhy solution,
$element = @things[rand @things];
because it was the simplest (and works).
I didn't quite see why you would have to do a +1 on
Rohesia Hamilton Metcalfe wrote at Thu, 30 May 2002 17:28:45 +0200:
> #make array of cgi-scripts:
> @Scripts=("f-.cgi", "f-bb.cgi", "f-.cgi", "f-.cgi", "f-ee.cgi",
> "f-ff.cgi");
>
> # pick one at random
> srand;
> $RandomScript = $Scripts[int(rand(@Scripts))];
>
I agre
On Thursday, May 30, 2002, at 11:44 , Jeff 'japhy' Pinyan wrote:
> On May 30, drieux said:
>
>>> $element = @things[rand @things];
>>
>> that works - but it makes me nervous...
>
> You've no need to feel uneasy. It doesn't work because of cruftiness --
I was perchance not clear - I had been d
On Thursday, May 30, 2002, at 11:13 , Jeff 'japhy' Pinyan wrote:
> On May 30, drieux said:
>
>>> srand;
>>> $RandomScript = $Scripts[int(rand(@Scripts))];
>>>
>> my $RandomScript = $Scripts[int(rand($#Scripts + 1))];
[..]
> Don't worry. rand() requires its argument to be a scalar, so rand(
On Thursday, May 30, 2002, at 08:28 , Rohesia Hamilton Metcalfe wrote:
[..]
>
> Any help much appreciated.
>
> Rohesia
perlsonally I'm a fore and aft fan and would have done it like
my $fore = 'f-';
my $aft = '.cgi';
my $ScriptName = $1 if ($RandomScript =~ /$fore # all
On May 30, drieux said:
>> srand;
>> $RandomScript = $Scripts[int(rand(@Scripts))];
>>
> my $RandomScript = $Scripts[int(rand($#Scripts + 1))];
>
>I am also a bit concerned with trying to seed rand() with a
>list, rather than say, the count of the list as noted above.
>
>never be afraid to
On Thursday, May 30, 2002, at 08:28 , Rohesia Hamilton Metcalfe wrote:
> # pick one at random
> srand;
> $RandomScript = $Scripts[int(rand(@Scripts))];
>
> #here's the non-working regex:
> $ScriptName =~ s/$RandomScript/\w{3,}\b/;
>
> $RandomScriptURL = "path/".$ScriptName.".htm";
>
> ###
On May 30, Rohesia Hamilton Metcalfe said:
>#!/usr/local/bin/perl5
>use CGI qw(:standard);
>
>#make array of cgi-scripts:
>@Scripts=("f-.cgi", "f-bb.cgi", "f-.cgi", "f-.cgi",
>"f-ee.cgi", "f-ff.cgi");
>
># pick one at random
>srand;
>$RandomScript
10 matches
Mail list logo