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

Quoting और Interpolation

Double quotes आपके लिए variables भर देते हैं, और single quotes हर character को exactly जैसा type हुआ वैसे रखते हैं।

Quoting और Interpolation

Double quotes के अंदर, Perl variables को इनकी values से replace करता है और \n और \t जैसे escapes समझता है। Single quotes दोनों में से कुछ नहीं करते, सिवाय इसके कि \' और \\ फिर भी काम करते हैं। q() और qq() operators single और double quotes के alternatives हैं जो आपको अपने delimiters चुनने देते हैं, जो तब handy है जब text में ही quotes हों।

Note: जब interpolation को clear boundaries या एक calculation चाहिए तो ${name} या @{[ expression ]} इस्तेमाल करें।

उदाहरण: Quoting and interpolation

perl
use strict;
use warnings;

my $name = "Perl";
my @langs = ("Perl", "C");
print "Hello, $name!\n";
print 'Hello, $name!\n', "\n";
print "Suffix: ${name}_script\n";
print "Array: @langs\n";
print "Email: user\@example.com\n";
print "Sum: @{[ 2 + 3 ]}\n";
print qq(He said "hi" to $name\n);
print q(It's literal: $name), "\n";

# Output:
# Hello, Perl!
# Hello, $name!\n
# Suffix: Perl_script
# Array: Perl C
# Email: [email protected]
# Sum: 5
# He said "hi" to Perl
# It's literal: $name
{# 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. यह उम्मीद करना कि single quotes के अंदर variables replace होंगे
  2. एक double-quoted email address में @ escape करना भूल जाना
  3. $name_text लिखना जब आपका मतलब ${name}_text से था
चैप्टर सारांश
  • Double quotes variables और escapes interpolate करते हैं
  • Single quotes literal हैं
  • q() और qq() custom delimiters चुनते हैं
  • एक variable name का अंत mark करने के लिए ${name} इस्तेमाल करें
🔒

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.