On Aug 1, 2007, at 8:31 AM, Amiri Barksdale wrote:
Thanks Michael! I appreciate your response.
Can you possibly tell me what you mean with the "next unless"
statement? It seems to say go to the next upload object, i.e., the
next file, unless this one is numbered? But most of them will be
numbered, so it won't go... to the next one?
you are correct, it would typically not skip that field, since you
expect all fields to be numbered, assuming your javascript is working
correctly and your users don't try anything malicious.
but since the code below the next relies on it having a successful
$id to use as a key for the hash, i find it wise to test for such
assumptions just in case something goes awry.
as you can guess from the comment, that was taken from some of my own
code where javascript creates upload fields attach.1 .. attach.n -- i
see now that i changed the regex for you, but not the comment. :)
I am a straight-up amateur as you can probably tell from what I
posted--do you know of any resources where I can learn about how to
do these nested loops?
well, there is the usual o'reilly library of perl resources -- the
llama book, camel book, perl algorithms, perl best practices ...
there are also some simple web resources at http://perlmonks.org/?
node=Tutorials that might help you get started.
Amiri
On 7/31/07, Michael Reece <[EMAIL PROTECTED]> wrote:
can't you pass a field name to $r->upload()?
my $upload = $r->upload($thash{file});
$thash{filename} = $upload->filename;
$thash{fh} = $upload->fh;
or, from the other perspective, using $r for the outer loop:
foreach my $upload ( $r->upload ) {
next unless $upload->name =~ m{^file-(\d+)$}; # Must
match attach.n or it's not mine!
my $id = $1;
$thash{$id} = { filename => $upload->filename, fh =>
$upload->fh };
foreach my $attr ( grep /-\d+$/, keys %ARGS ) {
my ($key) = $attr =~ /^(.*)-\d+$/;
# validate $key if desired..
$thash{$key} = $ARGS{$attr};
}
}
[..snip..]
-------------------------------------------------------------------------
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