Concatenation और Repetition
dot strings को साथ जोड़ता है और x इन्हें repeat करता है।
In this page:
Concatenation और Repetition
. operator दो strings concatenate करता है, और .= एक existing variable में append करता है। x operator एक string को एक दी गई संख्या बार repeat करता है, जो lines draw करने के लिए useful है। जब x को इसके left पर parentheses में एक list के साथ इस्तेमाल किया जाए यह string की बजाय list repeat करता है।
Note:
Interpolation आमतौर पर . operators की एक chain से पढ़ना आसान है।
उदाहरण: Concatenation and repetition
use strict;
use warnings;
my $first = "Hello";
my $second = "World";
my $greeting = $first . ", " . $second . "!";
print "$greeting\n";
my $text = "abc";
$text .= "def";
print "$text\n";
print "-" x 20, "\n";
print "=" x 0, "|empty|\n";
my @zeros = (0) x 5;
print "zeros: @zeros\n";
print "Total: " . (2 + 3) . "\n";
# Output:
# Hello, World!
# abcdef
# --------------------
# |empty|
# zeros: 0 0 0 0 0
# Total: 5
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- strings concatenate करने के लिए + इस्तेमाल करना
- यह भूल जाना कि negative count वाला x एक empty string देता है
- (0) x 5 लिखना और एक list की बजाय एक string की उम्मीद करना
चैप्टर सारांश
- . strings concatenate करता है
- .= एक variable में append करता है
- x एक string repeat करता है
- (list) x n एक list repeat करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: