in reply to help in ruby code to perl
#!ruby # # Cut header of SPL in spool folder to raw EMF # def spl2emf(fnm) File.open(fnm + ".emf", "wb") {|fo| File.open(fnm, "rb") {|fi| str = fi.read pos = str.index(" EMF") if pos == nil print "No EMF marker found; probably wrong file\n" next end fo.write(str[(pos-40)..-1]) } } end if __FILE__ == $0 ARGV.each {|fnm| print fnm, "\n" spl2emf(fnm) } end
This should be close (UNTESTED):
#!/usr/bin/perl # # Cut header of SPL in spool folder to raw EMF # sub spl2emf { my $fnm = shift; if ( open my $FO, '>:raw', "$fnm.emf" ) { if ( open my $FI, '<:raw', $fnm ) { read $FI, my $str, -s $FI; my $pos = index $str, ' EMF'; if ( $pos == -1 ) { print "No EMF marker found; probably wrong file\n"; return; } print $FO substr $str, $pos - 40; } } } foreach my $fnm ( @ARGV ) { print "$fnm\n"; spl2emf( $fnm ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: help in ruby code to perl
by ikegami (Patriarch) on Sep 20, 2009 at 15:16 UTC | |
by jwkrahn (Abbot) on Sep 20, 2009 at 17:30 UTC | |
by ikegami (Patriarch) on Sep 20, 2009 at 17:51 UTC | |
by jwkrahn (Abbot) on Sep 20, 2009 at 18:44 UTC | |
by ikegami (Patriarch) on Sep 20, 2009 at 18:55 UTC |