#!/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 �ıkarır ve �ıkarılan karakteri d�nd�r�r. Liste veya string ile �alışabilir.
$s1 =
"ozx";
print "$s1 : ",
chop($s1) ,
"\n";
<:vspace>
# chomp: Sadece $/ input record seperator'a atanan karakteri �ıkarır. �ntanımlı olarak "/n"
# Liste veya string ile �alışabilir.
$s1 =
"oz\n";
print chomp($s1) ,
"\n";
print "$s1 \n";
<:vspace>
# index: Aranan kelimenin ilk g�r�ld�ğ� 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ştirerek, string oluş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;