Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: wait command syntax

by nefigah (Monk)
on Mar 20, 2008 at 07:52 UTC ( #675179=note: print w/ replies, xml ) Need Help??


in reply to Re: wait command syntax
in thread wait command syntax

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; }


Comment on Re^2: wait command syntax
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://675179]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-07-30 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (241 votes), past polls