← Back to Perl Course | Chapter 3: Strings | Lesson 2 of 7

Concatenation और Repetition

dot strings को साथ जोड़ता है और x इन्हें repeat करता है।

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

perl
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
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. strings concatenate करने के लिए + इस्तेमाल करना
  2. यह भूल जाना कि negative count वाला x एक empty string देता है
  3. (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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.