[vox-tech] ruby (was: hold on to your hats - perl vs python)

Rod Roark vox-tech@lists.lugod.org
Thu, 18 Jul 2002 16:49:13 -0700


On Thursday 18 July 2002 04:30 pm, Henry House wrote:
> ...
> I like writing
>
> =09=09'a b c d'.split(/\s/).each do |i|
> =09=09=09puts "elem =3D #{i}"
> =09=09end
>
> than
>
> =09=09foreach my $i (split(/\s/, "a b c d")) {
> =09=09=09print "elem =3D $i\n"
> =09=09}

Actually the Perl version can be a bit more succinct:

  for (split /\s/, "a b c d") {print "elem =3D $_\n"}

BTW does ruby let you do one-liners as in perl -e?

-- Rod
   http://www.sunsetsystems.com/