Timothy:

Thank you for your response. As you can probably tell from the structure of
my loop, I am by no means a Perl professional or expert--could you please
possibly explain to me what is going on in the first loop you post? I can't
quite unpack it. I understand that you're adding some sort of index to each
file's fields, but it's murky.

If you don't have the time to do that, could you perhaps point me somewhere
where I can read about this sort of algorithm?

Amiri


Timothy S. Nelson wrote:
> 
>       I've never had to deal with file uploading, but the following code 
> should be a shorter version of what you have above:
> 
> ----------------------------------------
> foreach $key (keys %ARGS) {
>       $basekey = $key;
>       $num = ($basekey !~ s/-(\d+)$//) ? 1 : $1;
>       $bighash->{$num}->{$basekey} = $ARGS{$key};
> }
> 
> foreach $filenum (keys %$bighash) {
>       $file = $bighash->{$filenum};
>       # Do something with $file here
>       $nfile = $api->newBean('file');
>       $nfile->save($api);
> }
> ----------------------------------------
> 
>       Ok, so I left out the "my" statements, but still, it's shorter and 
> faster, and will automatically deal with new kinds of keys.  Tip: Data 
> Structures + Algorithms = Programs.  If you do clever things with data 
> structures, you can usually have a simpler program.  Designing your data 
> structure before you start your algorithm can help.
> 
>       Anyway, hopefully adding an extra loop will no longer seem too 
> onerous.  Or you could try to figure out some way to link the two loops 
> together with a data structure.
> 
>       :)
> 

-- 
View this message in context: 
http://www.nabble.com/Processing-Multiple-File-Uploads--tf4194009.html#a11947800
Sent from the Perl Mason - Users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to