From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Greg VisionInfosoft Sent: 05 April 2013 21:16 To: Perl-Win32-Users@listserv.ActiveState.com Subject: confused by use of 'implied' variable
> im butchering a public script i found on the internet for purpose of doing a > CGI file upload. Be very careful, there is a lot of poor quality scripts out there. > > 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; > } Not unreasonable, but you should restrict the scope of your variable to the while loop. while (my $data = <$upload_filehandle> ) { etc. > > 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). The implied variable here is $_, not @_. > > 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.=; You have to be explicit here. That is... $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? Start with 'perldoc perlvar'. It is the first one listed under General Variables. HTH -- Brian Raven ________________________________ Please consider the environment before printing this e-mail. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs