Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: New Perl User Question

by edebill (Scribe)
on Feb 02, 2002 at 18:24 UTC ( [id://142946] : note . print w/replies, xml ) Need Help??

in reply to New Perl User Question

people seem to have missed the rather idiomatic:

while(my $data = <>){ process the line of data }

<> in a while like this is a special case, and will automatically open any files listed on the command line, or read from standard input. You should be able to save out $processfilename=$ARGV[0]; beforehand for use in making your $cleanfilename. Using this construct saves you from needing to manually open and close the file.

Using my where you first use your variables is more readable than "declaring" them beforehand. This is one of the shortcomings of C, that every language since seems to have gone out of their way to overcome.

A little indentation would also make your code a little easier to parse visually :-)

Oh, and you might not want to unconditionally decrement $datalengthtrack after a chomp(). Chomp doesn't always remove characters, so depending on the input dataset, you might get errors. It DOES however return the number of chars removed, so you can capture that info and use it ($datalengthtrack -= chomp($data); or the like)