My first Perl one-line script

Once I found cool articles about using Perl in command line. Today I created my own one line script. By some reason Apache 2 escape \n and \t in its log:

tail -f /var/log/httpd/videoguide-error_log


[Tue Dec 13 23:46:26 2005] [error] [4401]ERR: 24: Error in Perl code: VG::Users can't SELECT id\nFROM Users\nWHERE login = ?\n: DBD::mysql::st execute failed: Unknown column 'login' in 'where clause' [for Statement "SELECT id\nFROM Users\nWHERE login = ?\n"] at /usr/lib/perl5/site_perl/5.8.6/DBIx/ContextualFetch.pm line 51.

It’s very difficult to read this information and I didn’t find information how to fix it on Apache level. Instead I use Perl:

tail -f /var/log/httpd/videoguide-error_log | Perl -e 'while(<>) { s#\\n#\n#g; s#\\t#\t#g; print; }'

and result is very good:

[Tue Dec 13 23:46:26 2005] [error] [4401]ERR: 24: Error in Perl code: VG::Users can't SELECT id
FROM Users
WHERE login = ?
: DBD::mysql::st execute failed: Unknown column 'login' in 'where clause' [for Statement "SELECT id
FROM Users
WHERE login = ?
"] at /usr/lib/perl5/site_perl/5.8.6/DBIx/ContextualFetch.pm line 51.

UPDATED: the latest version one-liner:

Once I found cool articles about using Perl in command line. Today I created my own one line script. By some reason Apache 2 escape \n and \t in its log:

tail -f /var/log/httpd/videoguide-error_log


[Tue Dec 13 23:46:26 2005] [error] [4401]ERR: 24: Error in Perl code: VG::Users can't SELECT id\nFROM Users\nWHERE login = ?\n: DBD::mysql::st execute failed: Unknown column 'login' in 'where clause' [for Statement "SELECT id\nFROM Users\nWHERE login = ?\n"] at /usr/lib/perl5/site_perl/5.8.6/DBIx/ContextualFetch.pm line 51.

It’s very difficult to read this information and I didn’t find information how to fix it on Apache level. Instead I use Perl:

tail -f /var/log/httpd/videoguide-error_log | Perl -pe ' s#\\n#\n#g; s#\\t#\t#g'

Published by

Michael Stepanov

Site owner and admin :)

4 thoughts on “My first Perl one-line script”

  1. You are completely right. I forgot about this command line option 🙂
    The new version is:


    tail -f /var/log/httpd/videoguide-error_log | Perl -pe 's#\\n#\n#g; s#\\t#\t#g;'

Leave a Reply

Your email address will not be published. Required fields are marked *