Greg --

The "shortcuts" us the perl variable $_. That is, when no specific argument
is supplied, $_ is used by default.

  s/x/y/;
  while ( <> ) {...}
  print;

All the above and more expect a value to work with, and if none is given,
perl uses $_ by default.

You get into trouble when you have a loop that refers to $_ which then
calls a subroutine that does something else with $_...

See http://perldoc.perl.org/perlvar.html#General-Variables for details on
$_.

Your $aggregated_file_contents example wouldn't work, by the way: there's
no default variable in that context. You'd have to do this:

  $aggregated_file_contents .= $_ ;

Hope this helps!



On Friday, April 5, 2013, Greg VisionInfosoft wrote:

> im butchering a public script i found on the internet for purpose of doing
> a CGI file upload.
>
> theres one excerpt from the script that ive never used before.  the few
> lines...
>
> while ( <$upload_filehandle> ) {
>    print UPLOADFILE;
> }
>
> if it were me, i would not write code this way, i write in a way that make
> it easier for me to quickly understand what i was trying to do.  if it were
> me coding this in my 'lame' (for idiots) way, it would look more like...
>
> while ( $data = <$upload_filehandle> ) {
>    print UPLOADFILE $data;
> }
>
> but now that ive seen the code, as originally presented, it does cause me
> to ask the question...
>
> how does one know under what set of circumstances can such 'abbreviated'
> code be written?  in other words, how can one know what kinds of features
> or operations can use the implied variable @_ (which I assume is the
> variable that would be used in this case).
>
> specifically, if i wanted to append to a variable
> $aggregated_file_contents, each new block of the file as it was being read
> and output...
>
> my thought was to try:
>
> while ( <$upload_filehandle> ) {
>    print UPLOADFILE;
>    $aggregated_file_contents.=;
> }
>
> as opposed to what i would have normally done ($aggregated_file_contents
> .= $data;)
>
> yes, i know i can simply try it, to see if it works - but is there a more
> general rule one can follow that tells them when this kind of thing can
> normally be used, versus when not?
>
> thanks alot for any insights here
>
> greg
>


-- 
 Will Trillich :: 812.454.6431

“Grading takes away all the fun from failing. And a huge part of education
is about failure.”  -- Shimon Schocken
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to