LPM: RE: join
repett0 at sac.uky.edu
repett0 at sac.uky.edu
Sun Apr 2 21:10:52 CDT 2000
ok so how do you get the length of the array?? thats the main question
now...
Ron
On Sun, 2 Apr 2000, Rich Bowen wrote:
> repett0 at sac.uky.edu wrote:
> >
> > thanks, now I see the problem (I think :)) you need to use brackets. I
> > assumed that you get one line for free like c/c++ or java. One more ?,
> > how do you get the length. Im doing it like this now...
> >
> > #!/usr/local/bin/perl
> >
> > for($i = 0; $i < 10; $i++)
> > { $foo[$i] = int(rand(10));print "$foo[$i]\n";}
>
> That works.
>
> -OR-
>
> $foo[$_] = int(rand(10)) and print "$foo[$_]\n" for (1..10);
>
> But then, I'm usually an advocate of readability, and so I'd probably
> write it as
>
> for (1..10) {
> $foo[$_] = int(rand(10));
> print "$foo[$_]\n";
> }
>
> Or, better yet,
>
> foreach $i (1..10) {
> $foo[$i] = int(rand(10));
> print "$foo[$i]\n";
> }
>
> After all, TIMTOWTDI _is_ the motto of Perl.
>
> I never use the "for (;;)" syntax if I can avoid it. Somehow, it seems
> rather cumbersome to me. But it might be more comfortable to a C
> programmer.
>
> Rich
> --
> http://www.ApacheUnleashed.com/
> Lexington Perl Mongers - http://lexington.pm.org/
> PGP Key - http://www.rcbowen.com/pgp.txt
>
More information about the Lexington-pm
mailing list