Recent Changes - Search:

edit SideBar


Firefox 2
Get Thunderbird!

Strings

#!/usr/bin/perl
#
# String Manipulation
#
<:vspace>
use strict;
use warnings;
<:vspace>
my ($s, $s1, $s2, $s3);
my (@l, @l1, @l2);
<:vspace>
# q
#$s = q(Don't let yourself go);
#print "$s \n";
<:vspace>
# qq
$s = qq(I said: "go away");
print "$s \n";
<:vspace>
<:vspace>
# identifier
print <<EOF;
        Hey
        man
        i am alive
EOF
<:vspace>
# identifier
$s =<<EOF2;
go
go
go
EOF2
print "$s \n";
<:vspace>
# identifie ''
$s =<<'EOF';
oz@kozgun.net
EOF
print "$s \n";
<:vspace>
# identifie ""
$s =<<"EOF";
oz\@kozgun.net
oz\nat\nkozgun.net
EOF
print "$s \n";
<:vspace>
#substr
$s1 = "Hey man  i am alive";
$s2 = substr($s1, 4, 4, "girl");
$s3 = substr($s1, -4, 4);
print "$s1 - $s2 - $s3\n";
<:vspace>
# uc, lc
print uc($s1), "\n";
print lc($s1), "\n";
<:vspace>
# ucfirst, lcfirst
print ucfirst($s1), "\n";
print lcfirst($s1), "\n";
<:vspace>
# length
print "length: " , length($s1) , "\n";
<:vspace>
# chop: Son karakteri �&#305;kar&#305;r ve �&#305;kar&#305;lan karakteri d�nd�r�r. Liste veya string ile �al&#305;&#351;abilir.
$s1 = "ozx";
print "$s1 : ", chop($s1) , "\n";
<:vspace>
# chomp: Sadece $/ input record seperator'a atanan karakteri �&#305;kar&#305;r. �ntan&#305;ml&#305; olarak "/n"
# Liste veya string ile �al&#305;&#351;abilir.
$s1 = "oz\n";
print chomp($s1) , "\n";
print "$s1 \n";
<:vspace>
# index: Aranan kelimenin ilk g�r�ld�&#287;� yerin indexini d�nd�r�.
# Bulunanamazsa -1 d�ner.
$s1 = "oz ko";
$s2 = index($s1, "ko", 0);
print "$s2 \n";
<:vspace>
# rindex: tersten arama yapar.
$s1 = "perl perl perl";
$s2 = rindex($s1, "perl");
print "$s2 \n";
<:vspace>
# join: Bir listeyi verilen seperator ile birle&#351;tirerek, string olu&#351;turur.
@l1 = qw(red green blue);
$s1 = join(",", @l1);
$s2 = join(" and ", @l1);
print "$s1 \n";
print "$s2 \n";
<:vspace>
# split: Bir stringi verilen ayra�a g�re b�l�p bir listeye atar.
$s1 = "red,blue,green";
@l1 = split(/,/,$s1,2); #Limit 2
@l2 = split(/,/,$s1);
print "@l1 \n";
print "@l2 \n";
<:vspace>
# tr: Translation operator.
$s1 = "win win win";
$s1 =~ tr/w/l/;
print "$s1\n";
$s1 =~ tr/[a-z]/[A-Z]/;
print "$s1\n";
$s1 = "ABCDEFGH";
$s1 =~ tr/ABCD/ab/d; #CD silinir.
print "$s1\n";
$s1 = "peeerrllll pppppeerrrrll";
$s1 =~ tr/[a-z]/[a-z]/s; # veya tr/[a-z]//s
print "$s1\n";
<:vspace>
# printf
printf "%s %2d\n", "onuc", 13,33;

Edit - History - Print - Recent Changes - Search
Page last modified on July 13, 2005, at 03:53 AM