Paul - The Programmer

simple & stupid
Clearcase find
character cast by Perl

Perl format string

paul posted @ Thu, 17 Jul 2008 06:37:35 +0800 in coding life , 1365 readers

Strings can be formatted to your liking using formatting characters. Some of these characters also work to format files created in PERL. Think of these characters as miniature functions.

Character Description
\L Transform all letters to lowercase
\l Transform the next letter to lowercase
\U Transform all letters to uppercase
\u Transform the next letter to uppercase
\n Begin on a new line
\r Applys a carriage return
\t Applys a tab to the string
\f Applys a formfedd to the string
\b Backspace
\a Bell
\e Escapes the next character
\0nn Creates Octal formatted numbers
\xnn Creates Hexideciamal formatted numbers
\cX Control characters, x may be any character
\Q Do not match the pattern
\E Ends \U, \L, or \Q functions

formattingcharacters.pl:

#!/usr/bin/perl

print "content-type: text/html \n\n"; #HTTP HEADER

# STRINGS TO BE FORMATTED
$mystring = "welcome to tizag.com!"; #String to be formatted
$newline = "welcome to \ntizag.com!";
$capital = "\uwelcome to tizag.com!";
$ALLCAPS = "\Uwelcome to tizag.com!";

# PRINT THE NEWLY FORMATTED STRINGS
print $mystring."<br />";
print $newline."<;br />";
print $capital."<br />";
print $ALLCAPS";

Original Link www.tizag.com/perlT/perlstrings.php

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.
  • No match
  • No match

Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter