Maybe you are trying to complicate this? I think you've got the pieces you need right there. Here's an experiment I just tried. Note how <a href="http://test2.pl">test2.pl</a> is the same as <a href="http://test.pl">test.pl</a>, but with the pipe to sed sucked into the program rather than built up as a pipeline on the command line...<br>
<br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">#!/opt/local/bin/perl</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">use warnings;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">use strict;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">foreach my $i ( 0 .. 40 ) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print "$i\n";</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">exit 0;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">richard-dice-s-computer-9:Desktop rdice$ perl <a href="http://test.pl">test.pl</a> | sed -n '10,20p'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">9</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">10</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">11</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">12</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">13</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">14</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">15</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">16</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">17</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">18</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">19</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">richard-dice-s-computer-9:Desktop rdice$ cat <a href="http://test2.pl">test2.pl</a><br>#!/opt/local/bin/perl<br><br>use warnings;<br>use strict;<br><br>open TEST, "| sed -n '10,20p'";<br>
<br>foreach my $i ( 0 .. 40 ) {<br> print TEST "$i\n";<br>}<br><br>close TEST;<br><br>exit 0;<br>richard-dice-s-computer-9:Desktop rdice$ perl <a href="http://test2.pl">test2.pl</a><br>9<br>10<br>11<br>12<br>
13<br>14<br>15<br>16<br>17<br>18<br>19<br></span><br></div><br><br>On Mon, Dec 6, 2010 at 10:22 AM, Antonio Sun <<a href="mailto:antoniosun@lavabit.com">antoniosun@lavabit.com</a>> wrote:<br>> Hi, <br>> I have the following code in a loop:<br>
> open(OUTFILE, "$cmd >> myfile"); # append write <br>> print OUTFILE content();<br>> close(OUTFILE);<br>> The $cmd is a complicated sed command. For simplicity purpose, let's say it<br>
> is <br>> | sed -n '10,20p' <br>> I.e., printing only lines 10~20 of the content of each loop. <br>> My goal is to write to STDOUT instead of a fixed file. I tried to change the<br>> above open statement with<br>
> open(OUTFILE, "$cmd >-"); # write to STDOUT<br>> or,<br>> open(OUTFILE, "$cmd >>-"); # write to STDOUT<br>> but didn't get any output. <br>> Anyone can help me here? <br>
> BTW, in case you wonder why the open statement is in the loop -- if I don't<br>> do it this way and open outside the loop instead, I'll get the<br>> first 10~20 lines only from the first loop.<br>> Thanks<br>
> antonio<br>><br>><br>> _______________________________________________<br>> toronto-pm mailing list<br>> <a href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a><br>> <a href="http://mail.pm.org/mailman/listinfo/toronto-pm">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
><br>><br><br>