Friday, May 30, 2008

[perl] Regular expressions

* Oneliner to remove spaces at the beginning and at the end of a string (trim)
$string =~ s|^(\s*)(.*?)(\s*)$|$2|s;

* Replacing "::" by "/" . This can be useful when you want to see if you can load a module at run time

$module =~ s|::|/|g;
eval "require $module.pm";

No comments: