strredwolf has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing my own obfuscated atob/btoa v5 converter, and am trying to capture the output from dc (which does some of the dirty work). I'm half tempted to call myself again inside a pipe to convert the file... but here's what I have so far (with explination):

#!/usr/bin/perl -0777 $f=<STDIN>; #suck the whole file in. $d='16i[[z]P]sZ[[y]P]sY[la55~21+Sb55~21+Sb55~21+Sb55~21+'. 'Sb21+PLbPLbPLbPLbP]sX[?dsa0=Zla20202020=YlXxlAx]dsAx'; # DC Code. Basically take a 4 byte word and encode it into # 5 bytes. Until it gets the signal to quit, of course. open(DC,"|dc -e '$d' > out.d8a"); # open up DC while($f) { $f=~s/^(.{0,4})//s; $z=$1; $l+=length $z; # grab 4 bytes $z.="\0" while((length $z) < 4); # pad it to spec $z=unpack("H*",$z); print DC "\U$z\E\n"; # send it to DC } print DC "q\n"; # tell DC to quit.

--
$Stalag99{"URL"}="http://stalag99.keenspace.com";

Replies are listed 'Best First'.
Re: Caputuring output while inputting to dc...
by czarfred (Beadle) on Sep 21, 2001 at 22:08 UTC
    Maybe this example might help a bit (from the Perl Cookbook):

    use IPC::Open2; open2(*README, *WRITEME, $program); print WRITEME "here's your input!\n"; $output = <README>; close(README); close(WRITEME);


    You can either use typeglobs as used above, or you can use self-made IO::Handle objects and pass them in, as the open2 function will not create handles for you.

    Note that you do not need to use die with the open2 function, as it dies on error. If you need to know if it produced an error, wrap it in an eval block and test $@.

    I think IPC::Open3 module's args are different, and check out the IPC::Open2 and IPC::Open3 documentation for more detailed information.
Re: Caputuring output while inputting to dc...
by coolmichael (Deacon) on Sep 21, 2001 at 21:51 UTC
    I think you might want to look at IPC::Open2 and IPC::Open3. They handle bidirectional piping. I can't offer you any experience with them, but I've read about them.

    Michael

Re: Caputuring output while inputting to dc...
by blakem (Monsignor) on Sep 21, 2001 at 21:36 UTC