On Thursday 26 July 2001 02:30, you wrote:
First, do use strict and make the changes necessary to satisfy it. It's a
good habit to get into and would be a good learning experience to work it
into this code. This is not so much code that it would take all that long.
> open (ADDSRC, "data.csv") || die ("Unable to open file\n");
> @addsrc=<ADDSRC>;
> splice (@addsrc,0,1);
I'm curious why the splice here? You've just read all of your input data
into the array and now you just removed the first element. I used a test
file with two lines and the first gets spliced away leaving only the second.
I imagine that person who gets left on the cutting room floor might be
annoyed.
I have a couple other comments.
I'd use a HERE document of the hard coded header stuff you're including.
Specifically, the "Base level" information and the "staff list" information.
It's just cleaner than all the print statements.
My big problem is with the data structure you've used. You take each record
and split it up, storing each element of the record and storing it in an
array. So, what you get is an array, @data, containing a "first name" array
which contains all of the first names and a "surname" array that contains all
the surnames, etc. This is the dump ( using Data::Dumper ) of the data
structure based on my test data:
$VAR1 = [
[
'name',
'othername'
],
[
'surname',
' othersurname'
],
[
'[EMAIL PROTECTED]',
' [EMAIL PROTECTED]'
],
[
'56789',
'11111'
],
[
'molecular',
'biology'
]
];
You're really relying on the validity of your data to keep things all on an
even keel. What if you have bad data? Here's another dump:
$VAR1 = [
[
'name',
'othername'
],
[
'surname',
' othersurname'
],
[
'[EMAIL PROTECTED]',
' [EMAIL PROTECTED]'
],
[
'56789',
'biology
'
],
[
'molecular',
undef
]
];
Oops, there was bad data in the .csv file and now I have a department where
an extension should be, etc.
My suggestion would be to open the data file, process it a line at a time,
verify the data is good and then write it out as you go. At the very least,
I'd get rid of this @data array which seems to be unnecessary to me.
Anyway, it works as is but you could run into some problems down the line.
As an experiment, I added "use strict" and it only took me about a minute to
satisfy it. So, do give it a try.
Regards,
Troy Denkinger
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]