I normally work in unix, but this dual-boot laptop has WinXP, and sometimes I use that. So I installed the GNU cdrom of Windows ports, which works fine -- including the bash shell, which I use instead of "command.com", always. I also installed ActiveState Perl 5.8.2, and that seems to work also (bash handles perl scripts as executables nicely). But there's this little problem with using pipe commands to feed a perl script -- here's a demonstration:
bash$ ls
junk
test.junk
bash$ ls | sed 's/\./-.-/' # piping between GNU utils works
junk
test-.-junk
bash$ ls > junk
bash$ perl -pe 's/\./-.-/' junk # perl reading from a file works
junk
test-.-junk
bash$ perl -pe 's/\./-.-/' < junk # redirecting stdin from file works
junk
test-.-junk
bash$ ls | perl -pe 's/\./-.-/' # using a pipeline
# nothing comes out
# trying the pipe again, more carefully this time:
bash$ ls | perl -e 'while (<>) {
> s/\./-.-/;
> print;
> }
> print "all done\n";'
all done
When I step through that last example with "perl -de", it never enters the while loop -- the first attempt to read input with the diamond operator fails (or yields the equivalent of EOF), and execution goes directly to the last line.
Any clues or hints about what's going wrong here? What am I missing?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.