(This is cross-posted on devshed and perlguru due to not getting much answers)
This is a similar question to my previous one about modules but a more overhead question. The example is somewhat simplified.
Say you have a bunch of scripts like request.pl, modify.pl, transfer.pl, pending.pl etc.....
they all contain multiple subs where it reads a directory or contents of a comma separated file and will check for a variety of conditions so it can go on to modify or transfer or view etc.
Right now every script and alot of subs in them re-read the file or files in question, so alot of scripts have something like this, using a foreach, sometimes a while...etc
foreach my $file (@files) { chomp $file; my $filename = "$file"; (open(my $IF, '<', $filename)); my @entry = <$IF>; $lastentry = $entry[-1]; close $IF; chomp $lastentry; my @record = split(':', $lastentry); my $id = $record[0]; my $name = $record[1]; my $street = $record[2]; my $city = $record[3]; my $state = $record[4]; my $status = $record[5]; if (some condition like $status is active)( do something..... )
So I thought instead of all this re-reading, what if a module was called to just read the files once and do different things in different scripts. Read the files, split up the commas in to variables or something and have it in an array or hash....and then based on conditions do something
Example: in the modify script read the files and determine which are in status active and do stuff, and in move.pl determine if city is something specific and do something else with it but not have to re-read the file in each applicable sub and script. I'm sorta missing something because in all cases the file being read is in a while or for loop so what do I do? Just return the array from the module and split in each file or what? Does this make sense?
How would you do this?
---IconxIn reply to Discussion(maybe?) How would you do this? Modules and reading a file/dir by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |