in reply to Re: quoting/escaping file names
in thread quoting/escaping file names

Hello
Here's a pratical example
while(<>) { my $filename = q{$_}; $filename =~ s/\$/\\\$/; my $exec = `md5sum "$filename"`; print $exec ."\n"; }

My input
/mnt1/$Recycle.Bin/S-1-5-21-3093161954-3233498542-1968413288-3198/$I7Q +M78L.pdf<br> /mnt1/$Recycle.Bin/S-1-5-21-3093161954-3233498542-1968413288-3198/$ID8 +4PBU.pdf<br> /mnt1/$Recycle.Bin/S-1-5-21-3093161954-3233498542-1968413288-3198/$IDL +L4FU.JPG<br> /mnt1/$Recycle.Bin/S-1-5-21-3093161954-3233498542-1968413288-3198/$IE2 +ZPET.xls<br> /mnt1/$Recycle.Bin/S-1-5-21-3093161954-3233498542-1968413288-3198/$IF7 +3ZR5.jpg<br>

 find /mnt1/\$Recycle.Bin/ -type f | hash.pl The result ..
md5sum: $_: No such file or directory <br> md5sum: $_: No such file or directory <br> md5sum: $_: No such file or directory <br> md5sum: $_: No such file or directory <br>

But As I said before. file names could have spaces and quotes..

ps: I know there's a DIGEST::MD5. Its only an example

Replies are listed 'Best First'.
Re^3: quoting/escaping file names
by AppleFritter (Vicar) on Sep 09, 2014 at 07:50 UTC

    Try removing this line:

    my $filename = q{$_};

    q// (or q{} etc.) is just the single-quote operator; I used that instead of the more customary single quotes to avoid having to escape the single quote in the string itself (which I felt would only serve to complicate the issue).

    See Quote and Quote like Operators and Quote Like Operators in perlop. Since this IS a single-quote, BTW, q{$_} (which is exactly the same as '$_') does not interpolate $_ into the string, and you end up passing a literal $_ to md5sum. And of course, it's unlikely that a file with that name exists.

    Long story short, just remove that line, it was just there to provide an example filename to work with.

Re^3: quoting/escaping file names
by Anonymous Monk on Sep 09, 2014 at 06:20 UTC
    Why did you type  my $filename = q{$_}; what do you think that does?