blacksmith has asked for the wisdom of the Perl Monks concerning the following question:

I understand the concept of TIMTOWTDI and think it is a very intense, intriguing, thought-provoking, and accurate principle. So here is the situation. I am trying to write a program (AND yes I still consider myself $newbie) that will open a .txt file that will be formatted like so
'him@here.com','C:\\test1.txt','C:\\test2.txt','C:\\test3.txt' 'her@there.com','C:\\test3.txt' 'it@where.com','C:\\test2.txt','C:\\test1.txt'

and take the email address (which I planned for to always be placed first) and send the following files.
My question is, "what would be the most efficient?" I have looked at the perldsc pages and attempted a hash of hashes, but like I said earlier, I still consider myself a $newbie since I was having a tough time grasping the concepts fully. Things like how I should format the .txt file or should I use hashes or arrays were concerns. I realize that everyone may have a different idea and way. And though each way may be just as efficient in time and resource usage, there will be certain ways that are more efficient for the perlmonk and the monk's way of thinking. That is why I am asking in this manner. To find the most efficient path for my way of thinking.
Thanks.
Blacksmith.

Update:I need to send a seperate mail to ALL of the address when the program runs.

Added update 2001-12-07 by dvergin per user request

Replies are listed 'Best First'.
Re: Advice in deciding hash or array
by runrig (Abbot) on Sep 10, 2001 at 22:43 UTC
    It all depends on what you are doing with the data.
    Do you need to just scan through the file until you find the line(s) you want, or just process each line one at a time? Then there's no point in putting the whole file in any data structure. Just read one line at a time and process it without saving it.
    Do you need to repeatedly look up which files to send by email address? Then a hash of arrays (with email address as the key) is probably best.
    Do you need to repeatedly look up all addresses which send a certain file?
Re: Advice in deciding hash or array
by Albannach (Monsignor) on Sep 10, 2001 at 22:43 UTC
    Unless you are concerned that a particular e-mail address will appear on more than one line (and you would then put all the files for that address into one outgoing message), why not just process the file one line at a time and avoid storing it in memory at all?

    Perhaps you can elaborate on what you are going to do with these data. For example, if you want to make sure you only send one message to each address, and that no file is attached more than once to any message, read the whole file into a hash of hashes, which will ensure unique mail addresses and unique file names. This is the 'most correct' solution to me, but it would also probably consume the most memory (depending on how much redundancy there is in the data). As you said, TIMTOWTDI!

    --
    I'd like to be able to assign to an luser

Re: Advice in deciding hash or array
by suaveant (Parson) on Sep 10, 2001 at 22:49 UTC
    For simplicity's sake, I would probably do a hash of arrays if I was going to store them all beforehand, but why not just process line by line... for example...
    open(LIST, "list.txt") or die $!; my @files; while(<LIST>) { s/^'//; s/'\n?$//; @files = split /','/, $_; my $email = shift @files; ### $email holds email, @files holds files, so put ### code here to send email accordingly }

                    - Ant
                    - Some of my best work - Fish Dinner

(ichimunki) Re: Advice in deciding hash or array
by ichimunki (Priest) on Sep 10, 2001 at 22:53 UTC
    update: of course, as runrig points out, this all depends what you have planned for this data. there is more than one way to do it.

    That looks like a hash of lists, as in:
    my %files = ( 'him@here.com' =>[ 'test1.txt', 'test2.txt', 'test3.txt' +], 'her@there.com' => [ 'test3.txt' ], 'it@where.com' => [ 'test2.txt', 'test1.txt' ] ); or generically: my %files2; foreach( <LINE> ) { chomp; my ($email, @list ) = split( ',', $_ ); #assumes no commas in data f +ile! $files2( $email ) = \@list; } and access looks like: my @list_of_files = @{ $files2{ $email } };