in reply to Why is IPC::Open2 behaving differently in a .pm?

No way to tell without knowing what program is and does. I've coded program as follows

#!/usr/bin/perl $_ = <STDIN>; chomp; print "foo => '$_'";

and both the command line version and the module version worked as expected after changing

- print $in q|some json|; + print $in "some json\n";

Maybe you have to set local $| = 1; inside your MyPack.pm (see perlvars)? Looks like a buffering issue - despite --unbuffered ;-)

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: Why is IPC::Open2 behaving differently in a .pm?
by sendu (Initiate) on Aug 17, 2015 at 09:48 UTC
    With program as you specify it, both work. With my own program (baton-metaquery from https://github.com/wtsi-npg/baton), even with local $| set, it doesn't.

    However the question is why the 1-liner with the in-line MyPack package works, but copy/pasted MyPack code in to a .pm does not work. How can that be possible?

      Because that isn't the actual source of the difference. You have just convinced yourself that it is. And then you posted code but removed the parts that you don't think are the cause of the difference and people have shown that this incomplete code (when made to actually work) doesn't demonstrate that difference.

      The problem is in the parts that you didn't post.

      - tye        

        Yes, you're quite right. The problem was my json contained single quotes. If I removed them it works the same in both.