Alright, so here's my shot at a Perl version of the above. Note that there is quite a bit of commented-out code in the Python version, so I didn't reproduce that.

#!/usr/bin/env perl use warnings; use strict; use feature ':5.10'; use File::Find; use File::Basename; use IO::Uncompress::AnyUncompress; # Note: if this script isn't being run from the same directory as the # python one was, chdir to it! Or convert everything to absolute paths +. my $home = $ARGV[0] // q{./FFCache/}; # 5.10 idiom my $cachedata = q{../../Documents/cachedata/}; # The python script has some commented out stuff here, so I won't rewr +ite it find( { wanted => \&process_file, no_chdir => 1 }, $home ); sub process_file { my $name = basename( $File::Find::name ); # Needed because we are +running no_chdir return if $name =~ /_CACHE_/; my $content; my $data; my $gzip; if ( $gzip = new IO::Uncompress::AnyUncompress( $File::Find::name + ) ) { my $status = $gzip->read( $data ); return unless $status > 0; } else { open my $file, '<', $File::Find::name or return; $data = do { local $/; <$file> }; close $file; } # This seems like an odd way of doing the following, but it's # how the python script does it, so who am I to argue? if ( substr($data, 0, 10) =~ /PNG/ ) { $content = 'png'; } elsif ( substr($data, 0, 10) =~ /GIF89a/ ) { $content = 'gif'; } elsif ( substr($data, 0, 10) =~ /JFIF/ ) { $content = 'jpeg'; } elsif ( substr($data, 0, 20) =~ /HTML/i ) { $content = 'html'; } else { return; } my $fname = $cachedata . $name . '.' . $content; open my $f_out, '>', $fname or return; print $f_out $data; chmod 0777, $f_out; close $f_out; }

In reply to Re^2: wait command syntax by nefigah
in thread wait command syntax by jperlq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.