Home > Quick Hacks, Software Development > My first Perl one-line script

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’

Categories: Quick Hacks, Software Development Tags:
  1. December 14th, 2005 at 14:26 | #1

    You can use

    Perl -pe

    and get rid off the

    while

    loop. Like this:

    tail -f somefile | Perl -pe ‘s/some/other/g’
  2. December 14th, 2005 at 14:51 | #2

    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;'

  3. December 15th, 2005 at 01:39 | #3

    You don’t even need that last

    print

    statement in your code. The results will be printed out anyway. ;)

  1. February 15th, 2007 at 23:36 | #1
Get Adobe Flash playerPlugin by wpburn.com wordpress themes