Quoting और Interpolation
Double quotes आपके लिए variables भर देते हैं, और single quotes हर character को exactly जैसा type हुआ वैसे रखते हैं।
In this page:
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
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
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- यह उम्मीद करना कि single quotes के अंदर variables replace होंगे
- एक double-quoted email address में @ escape करना भूल जाना
- $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: