in reply to create image via binmode

Now that you mention $\ I remember I've seen this somewhere before. Can you give me an URL where I can read more on this special variable ? Thanks a lot Luca

Replies are listed 'Best First'.
Re^2: create image via binmode
by ikegami (Patriarch) on Jan 13, 2006 at 22:19 UTC
    I mentioned $/ (used for reading), not $\ (used for writing). Both are documented in perlvar.

      If the image is rather small, you could also try something like:

      my $imageContent = do { open (my $IN, "<", $image) or die "Error in reading '$image': $!"; binmode($IN); local $/ = undef; my $content = <$IN>; close($IN); return $content; }; # do open (my $OUT, ">", $outfile) or die "Error: couldn't write '$outfile': $!\n"; } # unless binmode($OUT); # thanks to pKai print $OUT $imageContent; close($OUT) or die "Error: couldn't close '$outfile': $!";
      or shorter:
      my $imageContent = do { open (my $IN, "<", $image) or die "Error in reading '$image': $!"; binmode($IN); local $/; # defaults to undef <$IN>; # close happens automatically at end of block if # you use a lexical variable as filehandle }; # do open (my $OUT, ">", $outfile) or die "Error: couldn't write '$outfile': $!\n"; binmode($OUT); # thanks to pKai print $OUT $imageContent; close($OUT) or die "Error: couldn't close '$outfile': $!";

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

        There is a binmode $OUT; missing, which will lead to rendering the output unusable under Win.
        That's the same as my first post, except you added do which doubles the memory usage.