[Classiccity-pm] basic idiot question

Paul Keck pkeck at uga.edu
Sun Nov 16 00:55:29 CST 2003


On Thu, Oct 30, 2003 at 11:05:01PM -0700, Jeff Scarbrough wrote:
> The final program is listed at 
> http://www.fishplate.org/perl/data_prep.txt  if you want to see how I made 
> it work.  I'd be interested in any critiques you folks can provide, as this 
> is not just a job, but also a learning experience...I'm curious to see if 
> there is a better solution.

It's been longer than I intended, but I do have a few comments.  

==========
1. You might find it easier to pass in the filename arguments on the command
line rather than prompting for them, a la:

./data_prep.pl file1 file2

You access these arguments through the @ARGV array, which is populated for
you automagically.  So then you could say

$fileroot_1 = shift @ARGV; #shifts one element off @ARGV and sticks it in there
open(INFILE, "$fileroot_1" . ".prn"); @array_1 = <INFILE>; close INFILE;

and then do it again for the next file.

In fact, I'd probably force them to type the whole name of each file instead
of tacking on .prn for them.  When you write this to handle abitrary numbers
of files, and you have a directory with just these files in it, they could
type

./data_prep.pl *

or, if there's other junk mixed in with the .prn files,

./data_prep.pl *.prn

==========
2. You have this line in there for each array processing loop:

  $_ =~ s/\\n//;            # Strip carraiage return from line

You could substitute

 chomp $_;

or just

 chomp; #by default it chomps $_

Which will take off trailing newlines, if they are there.  "chop" takes off
the last char of the line, whether it's a newline or not.  chomp is smarter. 
In fact, it's so smart you could, before your loop, do this:

chomp @array_1;

and it will do what you want- take off newlines from all the elements of
@array_1, if they exist.

===========
3. I'm not sure of everything you're doing with the $doyday stuff, but you
might get some benefit out of the Julian Day module from cpan.org:

http://search.cpan.org/~muir/Time-modules-2003.0211/lib/Time/JulianDay.pm

==========
4. What kind of program is taking the output of this one?  If it's one
you're writing, it might be better to have a somewhat different output
format, rather than having " , , , , , , , , , , , , , , " in there a bunch
of times.  The stuff I posted last time with the more complicated data
structure and the Data::Dumper module comes to mind- if you can free
yourself from the constriction of having all the data from a day on one line
in a file, yet still tell which day it all came from, you could perhaps make
it simpler.  Or at least it makes it easier to handle multiple files without
a bunch of hard-coded variables like @array_1 and @array_2.  

-- 
Paul Keck       pkeck at uga.edu         http://www.arches.uga.edu/~pkeck
University of Georgia                 http://www.uga.edu/ucns/telecom
EITS Network Engineering              mailto:pkeck at ediacara.org
    --Opinions mine.--                Go fighting anomalocaridids!!!



More information about the Classiccity-pm mailing list