← Back to Perl Course | Chapter 2: Variables | Lesson 1 of 7

Scalar Variables का परिचय

एक scalar एक single value hold करता है, जैसे एक number, text का एक piece, या एक reference।

In this page:

  1. Scalar Variables

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

perl
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
{# 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. एक scalar इस्तेमाल करते वक्त $ sigil भूल जाना
  2. use strict के अंतर्गत बिना declare किए एक variable इस्तेमाल करना
  3. यह मान लेना कि "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:

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.