in reply to Embed GIF in perl source?
Here's a simple script that converts a file to a hex encoding:
And here's a script that converts a hex encoding back to the original data:#!/usr/local/bin/perl -w # convert binary file to hex use strict; @ARGV or die "Usage: $0 <filename>\n"; my $file = shift; open(FH, $file) or die "Can't open $file: $!\n"; binmode(FH); my $buf; while (read(FH, $buf, 32)) { # 32 bytes fit nicely on one line when hex-encoded print unpack('H*', $buf), "\n"; } __END__
Of course, you could store the encoded gif in your script however you wish; a here doc would be an excellent way to do it.#!/usr/local/bin/perl -w use strict; $| = 1; while (<DATA>) { chomp; print pack('H*', $_); } __END__ 23212f7573722f6c6f63616c2f62696e2f7065726c202d770a0a2320636f6e76 6572742062696e6172792066696c6520746f206865780a0a7573652073747269 63743b0a0a4041524756206f7220646965202255736167653a202430203c6669 6c656e616d653e5c6e223b0a0a6d79202466696c65203d2073686966743b0a0a 6f70656e2846482c202466696c6529206f7220646965202243616e2774206f70 656e202466696c653a2024215c6e223b0a62696e6d6f6465284648293b0a0a6d 7920246275663b0a0a7768696c652028726561642846482c20246275662c2033 322929207b0a20207072696e7420756e7061636b2827482a272c202462756629 2c20225c6e223b0a7d0a
|
|---|