Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jun 272010
 

Wide character in print... warning in Perl

Answer:

Assume you have a simple script that print out UTF-8 characters in your script.

E.g.


#!/usr/bin/perl

my $foo = "Hello \x{4E2D} \x{570B}\n";   

print $foo;

When you run it, it will give out warnings...

Wide character in print at test.pl line 5.
Hello 中 國

To fix for the problem, add the line at the top of your program.

use encoding "utf-8";

Jun 262010
 

Run Perl with useful warnings

Answer:

For good programming habits, it is advised to run Perl using the -w flag so it will print out some useful warnings that might be useful for your program.

E.g.

# perl -e 'print $foo';

The above script shows nothing, but with the -w flag,

# perl  -w -e 'print $foo'; 
Name "main::foo" used only once: possible typo at -e line 1.
Use of uninitialized value $foo in print at -e line 1.

So you can see it is very useful for debugging your program.

In fact, the -w flag is the same as the warnings pragma

use warnings;

Jun 252010
 

Turn on all error reporting in PHP

Answer:

Sometimes, when debugging, it is helpful when you need to enable all PHP errors and make them visible in your application (not in the log), you can put the following line at the top of your script.

<?php

    error_reporting(E_ALL);