in reply to Re: escaping filenames taken in via user input
in thread escaping filenames taken in via user input

Minor nitpick for efficiency: don't do join '', <FH> - ever. Since you're only going to glue all the lines together anyway, don't ask for the file to be delivered line by line in the first place. Either localize $/ or use read. I'd do the first in this case.
if(..) { open my $fh, "<", $filename or die &cant_open_file; local $/ = \8192; # read in 8 kbyte chunks rather than line by lin +e print while <$fh>; }
See perldoc perlvar on the intricacies of $/. Note that this code uses a lexical to store the filehandle - it needs Perl 5.6 or newer to work that way, but affords us the luxury of not closing the file explicity. It just gets autoclosed when the $fh goes out of scope at the end of the block.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: escaping filenames taken in via user input
by stupidius (Initiate) on Oct 30, 2002 at 01:21 UTC
    You would be correct. I didnt even notice the join. I just pasted that part <blushes>. Just focused on using the \W on the filename. Good point!