Fwd: Re: [NCLUG] Looking at programming languages...

Chad Perrin perrin at apotheon.com
Thu Jan 17 12:21:26 MST 2008


On Wed, Jan 16, 2008 at 02:57:30PM -0700, Sean Reifschneider wrote:
> On Wed, Jan 16, 2008 at 08:38:44PM +0000, grant at amadensor.com wrote:
> >>> incredibly difficult Perl to read, there is no reason that Perl code
> >>> can't be written with the clarity of almost any other language.
> 
> >From my .signature list file:
> 
> The problem is, the people who would write "maintainable Perl" code
> are programming in Python.  -- Dann Frazier, 2002

Not really true.  I don't see Ovid, brian foy, chromatic, and Randal
Schwartz writing Python -- or me, for that matter.  I may not be the
world's greatest Perl programmer, but dammit, what I write in earnest is
*readable*.


> 
> > My issues with PERL are the built in variables related to regular
> > expressions are easy to get the wrong one, and that there are very
> 
> My biggest problem in Perl was that I always had problems passing a list to
> a function.  The function always wanted to unpack the list into separate
> arguments for the function.  I was never able to find the documentation
> that appropriately educated me on what the story with passing arguments to
> functions was.  This was back in 1996-ish, and I think I saw a reference to
> some documentation that "fixed" this, but by that time I was too happy with
> Python...

  #!/usr/bin/perl -l

  @foo = qw(one two three four five);

  funk(@foo);

  sub funk {
    @bar = @_;
    print foreach @bar;
  }

Like that.  Output:

  one
  two
  three
  four
  five

If you want to have a couple of scalars on the front, you can do
something like this:

  #!/usr/bin/perl -l

  @foo = qw(one two three four five);

  funk(@foo);

  sub funk {
    $bar = shift;
    $baz = shift;
    @qux = @_;

    print $bar;
    print $baz;
    print foreach @qux;
  }

There's probably a better way to do it, but I frankly haven't written any
Perl in about six months, and there's still rust on the gears.  You could
perhaps do some kind of multiple assignment:

  ($bar, $baz, @qux) = (shift, shift, @_);

. . . or:

  ($bar, $baz, @qux) = ($_[0], $_[1], $_[2 .. $#_]);

-- 
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Rudy Giuliani: "You have free speech so I can be heard."



More information about the NCLUG mailing list