AnyCompiler

Strings

Perl mein string literals ke do forms hote hain, aur ye jaan-boojh kar alag-alag behave karte hain. Double-quoted strings interpolate karte hain — isme likha gaya koi $scalar ya @array uski value se replace ho jaata hai. Single-quoted strings literal hote hain — inke andar kuch bhi expand nahi hota, isliye jab bhi string mein literal $ ya @ chahiye ho, ye right choice hote hain.

use strict;
use warnings;

my $name = "World";
print "Double-quoted: Hello, $name!\n";
print 'Single-quoted: Hello, $name!', "\n";
Output
Double-quoted: Hello, World!
Single-quoted: Hello, $name!

Strings . operator se concatenate hote hain (+ se nahi, jo numeric addition ke liye reserved hai). length, substr, uc, aur lc ordinary built-in functions hain, methods nahi — Perl ke strings objects nahi hain jin par aap methods call karte ho.

use strict;
use warnings;

my $first = "Perl";
my $second = "Rules";
my $combined = $first . " " . $second;
print "$combined\n";
print length($combined), "\n";
print substr($combined, 0, 4), "\n";
print uc($combined), "\n";
print lc($combined), "\n";
Output
Perl Rules
10
Perl
PERL RULES
perl rules

Next: numbers and operators — aur ye genuinely distinctive fact ki Perl mein comparison operators ke do completely separate sets hote hain, ek numeric aur ek strings ke liye.

Practice exercise

my $word = "perl" banao. uc($word) use karke uska uppercase version print karo, phir length($word) use karke uski length print karo.