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

Numbers और Operators

Perl में numbers और strings के लिए separate operators हैं, और यह आपके लिए conversion choose करता है।

In this page:

  1. Numbers और Operators

Numbers और Operators

Arithmetic + - * / % और exponent के लिए **, और increment operators ++ और -- इस्तेमाल करता है। dot operator . strings जोड़ता है और x इन्हें repeat करता है, जबकि == और eq क्रमशः numbers और strings compare करते हैं। Perl automatically convert करता है, इसलिए "10" + 5 15 है और 10 . 5 "105" है।

Note: / से division integer division नहीं है; result truncate करने के लिए int() इस्तेमाल करें।

उदाहरण: Numbers and operators

perl
use strict;
use warnings;

my ($a1, $b1) = (7, 2);
print "sum: ", $a1 + $b1, "\n";
print "division: ", $a1 / $b1, "\n";
print "integer part: ", int($a1 / $b1), "\n";
print "modulus: ", $a1 % $b1, "\n";
print "power: ", $a1 ** $b1, "\n";
print "join: ", $a1 . $b1, "\n";
print "repeat: ", "ab" x 3, "\n";
my $count = 5;
$count++;
$count += 10;
print "count: $count\n";
print "10 == 10.0 is ", (10 == 10.0 ? "true" : "false"), "\n";
print "'10' eq '10.0' is ", ('10' eq '10.0' ? "true" : "false"), "\n";

# Output:
# sum: 9
# division: 3.5
# integer part: 3
# modulus: 1
# power: 49
# join: 72
# repeat: ababab
# count: 16
# 10 == 10.0 is true
# '10' eq '10.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. strings compare करने के लिए == इस्तेमाल करना
  2. यह उम्मीद करना कि 7 / 2 3 देगा
  3. strings जोड़ने के लिए . की बजाय + इस्तेमाल करना
चैप्टर सारांश
  • Numeric operators + - * / % ** हैं
  • . strings जोड़ता है और x इन्हें repeat करता है
  • == numbers compare करता है और eq strings compare करता है
  • / एक floating-point result देता है
🔒

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.