Paul - The Programmer

simple & stupid

character cast by Perl

uppercase cast:

perl -p -e 's/(lowercase pattern)/\u$1/g'

perl -n -e 'print "\U$_"'

perl -p -e '$_="\U$_"'

lowercase cast:

perl -p -e  's/(uppercase pattern)/\l$1/g'

perl -n -e 'print "\L$_"'

perl -p -e '$_="\L$_"'

Perl format string

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

Clearcase find

cleartool find dir -follow -version '!lbtype(LABEL) && !version(\main\specific_branch\LATEST)' -print

Correct the comments in ClearCase

Since it's so important to give good comments for your changes. How to correct the unsuitable comments for a file you have already checked in or a label you have already created? Do we have the change to make the mistakes right?

Yes, of course. The answer is using the command chevent. 8-) The command chevent can replace or append the comments for the existing events. Its default behavior is to append existing comments.

For instance, correct the bad comments for the existing label my_label:

cleartool chevent -replace lbtype:my_label@my_vobs

For more information, just ask the clearcase man ( cleartool man chevent ).

Never do evil! 8-D

how to use the non-buffered stdout of Perl

At first, it's really a interesting bug.  I can't help writing it down.

I write a perl script which should be running quietly and infinitely on the background. I don't like to do writing the run-time log into a file directly in the script. So, I decide to just redirect the stdout to a file when I execute the script.

Now, here comes the werid bug. I start up the script. It works well. Everything is well except there is no log in the redirected stdout file. But after I disable the infinite loop, let it just run one time and exit.  Suprisedly,  the run-time logs appear in the redirected stdout file.

Fortunately, I realize that the problem of perl's output functionality at last.  With default behavior, Perl saves the output strings in a buffer instead of do phsical write to screen everytime. If I kill the script when it's running, then Perl doesn't have the opportunity to write the buffered strings to the screen. The solution is simply adding the code '$| = 1;'  to the begining of the script . It tells Perl using non-buffered I/O to the screen.

Furthermore,  in the case of using the non-buffered I/O to other device.  We can refer to the example below.

$oldh= select(DEV);

$| =1;

select($oldh);

Nice weekend.