in reply to Re: help on this code below
in thread help on this code below

i am uploading a file from a html file. that data is stored in filetoupload_02 field. and i am passing the user who has triggered this upload, that value is in pusr field. i want to know what values are coming into the perl file and what are their values this below code saying something about filetoupload_02 field and i want to know what is the value for pusr field also from the below code. when i am using $puser = $query->param("p_usr");but this value $puser i am not able to assign to any other variable i don't know why is that pls help
foreach $key (sort {$a <=> $b} $query->param()) { next if ($key =~ /^\s*$/); next if ($query->param($key) =~ /^\s*$/); next if ($key !~ /^filetoupload_(\d+)$/); $Number = $1;

Replies are listed 'Best First'.
Re^3: help on this code below
by aaron_baugher (Curate) on Oct 27, 2011 at 19:26 UTC

    A few observations:

    The first line loops through the CGI parameter keys (assuming $query is a valid CGI.pm object or something similar). They're sorted numerically, which is odd, and possibly pointless.

    The next line skips to the next key if this one is empty of anything but whitespace -- unlikely, and superseded two lines later by a more specific check.

    The next line skips to the next key if this one's value is empty of anything but whitespace.

    The next line skips to the next key if this one doesn't start with "filetoupload_" followed by one or more digits. If it does match that pattern, the digits are put in $Number by the next line and the loop proceeds on.

    Then after a blank line, your 'if' line checks the value of this filetoupload_\d+ parameter, and if it doesn't end in a forward or backward slash, puts everything after the last slash in $1, which the next line puts into $Filename.

    The next line puts $2 into $pxuser. But since there is only one set of capturing parentheses in the last regex, $2 will always be empty at this point, and thus so will be $pxuser. This is probably a problem.

    You also talk about getting a "p_usr" value, as well as a "pusr" value, but your code doesn't do this, and these are also not interchangeable. Where do you expect "the user who has triggered the upload" value to come from? Are "pxuser", "p_usr", and "pusr" three different things, or the same thing inconsistently typed?