I'm obviously missing here something in between how the perl loop works, tail -f and regex.
Setup:
@$ echo xab > a
Test:
@$ tail a | perl -pe 's/[^a]/*/g'
a
@$ tail -f a | perl -pe 's/[^a]/*/g'
... Nothing!!
Discussion:
maybe it's loop? but this also hangs:
@$ tail -f a | perl -e 'while (<>){s/[^a]/*/g}continue{die "-p destination:$!\n" unless print $_;}'
it could be /g, because this works
@$ tail -f a | perl -pe 's/[^a]/*/'
ab
it could be -pe, because this works
@$ tail -f a | perl -lpe 's/[^a]/*/g'
a
it could be regex, because this works
@$ tail -f a | perl -pe 's/x|b/*/g'
a
I'm lost. What's going on here?
The difference between those that "work" and those that don't is whether a LF was printed or not.
When their STDOUT is connected to a terminal, many programs will flush it on a LF or when the associated buffer becomes full. Perl follows this pattern, and those conditions haven't been met yet in the cases where you don't immediately see some output.
Adding the following will disable buffering on STDOUT:
BEGIN { $| = 1; }