Scalar Variables का परिचय
एक scalar एक single value hold करता है, जैसे एक number, text का एक piece, या एक reference।
In this page:
Scalar Variables
Scalar variable names एक dollar sign से शुरू होते हैं, और आप इन्हें my से declare करते हैं। एक scalar एक number या एक string hold कर सकता है, और Perl ज़रूरत पड़ने पर इनके बीच convert करता है। एक scalar जिसे कोई value नहीं दी गई undef है, जिसे आप defined से test कर सकते हैं।
Note:
Values 0, "0", "" (empty string), और undef false हैं; बाकी सब, "0.0" और "00" समेत, true है।
उदाहरण: Scalar variables
use strict;
use warnings;
my $name = "Ada";
my $age = 36;
my $price = 9.99;
my $nothing;
print "$name is $age years old\n";
print "Price with tax: ", $price * 1.2, "\n";
print "nothing is ", (defined $nothing ? "defined" : "undef"), "\n";
print "0.0 is ", ("0.0" ? "true" : "false"), "\n";
print "0 is ", (0 ? "true" : "false"), "\n";
# Output:
# Ada is 36 years old
# Price with tax: 11.988
# nothing is undef
# 0.0 is true
# 0 is false
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- एक scalar इस्तेमाल करते वक्त $ sigil भूल जाना
- use strict के अंतर्गत बिना declare किए एक variable इस्तेमाल करना
- यह मान लेना कि "0.0" false है
चैप्टर सारांश
- Scalars $ से शुरू होते हैं
- इन्हें my से declare करें
- एक scalar एक value hold करता है
- undef मतलब कोई value नहीं और defined इसे test करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: