Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Using pack/unpack on a PNG file

by AnomalousMonk (Archbishop)
on May 26, 2015 at 03:12 UTC ( [id://1127748]=note: print w/replies, xml ) Need Help??


in reply to Using pack/unpack on a PNG file

my $ifh = open("<:raw", "./file-bar.png");

Wishful, also quite surprising that Perl seems happy with it even with warnings and strictures enabled. In any event, the "successful" result (1) of open-ing the file is assigned to  $ifh and this is packed and written (apparently also "successfully") to another file. But it's still junk.

c:\@Work\Perl\monks\sierpinski>perl -wMstrict -MData::Dump -le "my $ifh = open('<:raw', 'junk.txt'); dd $ifh; " 1
Can anyone explain to me how this works — with strictures enabled?


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^2: Using pack/unpack on a PNG file
by choroba (Cardinal) on May 26, 2015 at 07:08 UTC
    Documented behaviour:
    (...) if FILEHANDLE is an expression, its value is the real filehandle. (This is considered a symbolic reference, so use strict "refs" should not be in effect.)

    system 'echo abc > 1.txt'; open '<:raw', '1.txt' or die $!; print while readline '<:raw'; unlink '1.txt';
    Update: I wouldn't recomend it, though, as it's confusing to a reader :-) The file is still opened with default layers:
    print PerlIO::get_layers("<:raw"); # unixperlio
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      This is considered a symbolic reference, so use strict "refs" should not be in effect.

      Yes, but if strictures are enabled the example still runs (and strictures were also enabled above), so I'm still confused:

      c:\@Work\Perl\monks\sierpinski>perl -wMstrict -le "system 'echo abc > 1.txt'; open '<:raw', '1.txt' or die $!; print while readline '<:raw'; " abc

      Update: I wouldn't recomend it, though, as it's confusing to a reader ... Darn right!


      Give a man a fish:  <%-(-(-(-<

        We aren't trying to explicitly dereference the symbolic reference.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found