Tuesday, May 27, 2008

Chapter 11: Beyond Scalars - More Data Types

############################################################################################################
#Author: Leo
#Email: ahyeek@gmail.com
#Desc:
# The author has created some codes to test out during the learning process for the book called
# <Professional Perl Programming>, publisher: Wrox Pree Ltd, year in 2001
# ISBN: 1-861004-49-4.
#
#Summary:
# Examples code for <Professional Perl Programming>.
# Chapter 11: Beyond Scalars - More Data Types
#
############################################################################################################

my $string = "AAA:1xBBB:0.21xCCC:0.33xDDD:1";

my $rstring = $string;
$string =~ s/:/*/g;
print "Before replace string =>$rstring\n";

print "After replace string=>$string\n";


############################################################################################################
# The 'Split' function.
############################################################################################################
print "\nThe 'Split' function...\n";
my $text = "affy5;affy6;illumina";

my @values = split(";", $text);
foreach (@values){

print "Split value ==> $_\n";
}

############################################################################################################
# Test match specified string start with certain words.
############################################################################################################
my @html_string = (

"<!-- This is commented html.",
"This is commented html. <!-- Commented at the end.-->",
"Not commneted."
);
foreach my $item (@html_string){

if($item =~ m/^<!--*./){
print "[ $item ] is commented html!\n";
}

else{
print "[ $item ] is not commented html!\n";
}
}


############################################################################################################
# Test for multiple matches.
############################################################################################################
my @tag_html_string = (
"<tag>blablabla</tag>",
"<tag>bla<tag>blabl<tag>a</tag></tag></tag>",
"<Tag>bla<tAg>blabl<taG>a</tag></tag></tag>",
"<Tag>bla<tAg><tAg><tAg>blabl<taG>a</tag></tag></tag>",
"<tag id=blablabla /><tag id=blablabla /><tag id=blablabla />",

);
my $tag_to_detect = "<tag";
my $same_line_tag_to_close = "/>";
foreach my $item (@tag_html_string){

@detected_tag = $item =~ /($tag_to_detect[ >]|$same_line_tag_to_close)/ig;
foreach(@detected_tag){ print "[ $_ ],"; }

print "\n";
}

No comments: