[NCLUG] newbie perl question...

Tkil tkil at scrye.com
Fri Aug 17 00:22:13 MDT 2001


>>>>> "Luke" == S Luke Jones <luke at frii.com> writes:

Luke> I am writing some scripts in Perl and I'd like to reuse a couple
Luke> of functions I've written. Is there an EASY way to do this, or
Luke> do I have to figure out packages and blessed references and crap
Luke> like that?

you probably want to read over:

   perldoc Exporter

more nitty-gritty:

   perldoc perlmod
   perldoc perlmodlib

easy samples:

   http://slinky.scrye.com/~tkil/perl/Weekday.pm
   http://slinky.scrye.com/~tkil/perl/wd.pl

(the latter is a script that tests the former.)

as always, the hardest part will be coming up with an interface.
sure, that logic is pointy, but is "header_printed" a global?  when
does it get initialized?

in your particular case, take a look at what the "-a" command-line
flag does (in conjunction with "-n" or "-p", it does an implicit

  @F = split ' ', $_;

on each incoming line -- it acts more "awk"-like, thus the "a"...).
also, look at the magic "$," variable (perldoc perlvar).  it is
emitted between every item in a list that is printed.  instead of
doing:

  print join "\t", @fields;

you could do:

  $, = "\t";
  print @fields;

which doesn't seem like that much of a win, but if you do it a lot...

anyway.  hopefully this has given you some ideas.

t.





More information about the NCLUG mailing list