From Rohidekar

Jump to: navigation, search



How do I pad a string with blanks or pad a number with zeroes?

    # Right padding a string with blanks (no truncation):
    $padded = sprintf("%-${pad_len}s", $text);

To sort an array in ASCII (Alphabetical) order


HTML Generator for CGI scripts

Most of main() deals with putting together bits of HTML. For a real-world script, use something like HTML::Template or Template Toolkit instead of putting HTML directly in the script.

Find and Execute

  find . -name "*.jar" -exec jar -tvf {} \;

Regular Expressions, String manipulation ec

How do I use POSIX in regular expressions?

To use the POSIX character classes, they must be within another character class:

for(split(//,$line)) {
  if (/[[:print:]]/) { print; }

Using a POSIX class on its own:

if (/[:print:]/) { } # WRONG!

won't have the intended effect. The previous bit of code would match :, p, r, i, n, and t.

Appending strings

  • $html .= "



Include newline in regex wildcard

undef $/;

Capitalize first letter of word

$string =~ s/(\w+)/\u$1/g;
should work just fine

Personal tools