-2

I created this small little maintenance script to unescape HTML entities.

use HTML::Entities;

use warnings;

while ( <> ) {
    decode_entities($_);
}

The problem is, it produces no output when I pipe it through bash like so,

echo "&quot;a&quot;" | perl ../../tmp.pl
Borodin
  • 123,915
  • 9
  • 66
  • 138
  • 4
    Why would you expect there to be? The function doesn't print anything, it just modifies `$_`. – 123 Jun 14 '17 at 09:48

1 Answers1

1

If you want to see some output, you'd better print/say the return value:

use HTML::Entities;

use warnings;

while (<>) {
    print decode_entities($_);
}

Since in void context, the function modifies the string in-place, you could convert your script into a one-liner pretty easily:

perl -MHTML::Entities -pe 'decode_entities($_)'

Like a while (<>), loop, the -p switch loops over each line of the input (either standard input, or the filename arguments), with the addition of a print in the continue block, which is run once at the end of each iteration of the loop.

Tom Fenech
  • 65,210
  • 10
  • 85
  • 122