I though that if you put double quoutes around a variable value in Perl, Perl would know for example that "20" is a number. And that if you put variable value between single quotes like this "my $number = '20'. Perl would take it as a literal string.

I think you may have misread or misinterpreted something. "20" is exactly the same as '20' in perl. But if $z has value 20 then "$z" and '$z' are quite different.

#!/usr/bin/env perl use strict; use warnings; my $dql = "20"; my $sql = '20'; my $z = 20; my $dqv = "$z"; my $sqv = '$z'; print "dql: $dql\n"; print "sql: $sql\n"; print "dqv: $dqv\n"; print "sqv: $sqv\n";

The assignment to $dqv is what is known as interpolation. Double quotes do it but single quotes do not. See the "interpolates" column in the table in Quote and Quote-like Operators for the full list.

Note that by putting any sort of quotes around a numerical value you are essentially converting it into a string. $z above is a pure number the other variables are all strings. But Perl isn't strongly typed so you can get away with plenty of mixing and matching.

Addendum: The choice of variable names in this example might not be obvious. They are abbreviations for "double quoted literal", "single quoted literal", "double quoted variable" and "single quoted variable". (Thanks 1nickt for pointing out the lack of clarity).


In reply to Re^3: result is not listening to if by hippo
in thread result is not listening to if by prospect

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.