No, I meant print reverse($num)+0;, which extracts '1' from the integer 100, as the OP asked. He didn't ask about 52, 583, 47, or 32767, he asked about 100. ;)

Yours works too, of course. The difference being, yours works over any integer, and mine works for the integer 100, or any other integer where the leading digit contains a positive value and the subsequent digits are zero. But both extract 1 from 100.

He may also have meant all integers, or he may also have meant any integer with one leading significant digit and all trailing digits being zero. Or he may have meant only the integer 100, or maybe an integer beginning with 1 and followed by only zeros, or maybe he meant only positive integers, or maybe something else entirely, but he said an integer, 100. Any other assertion is guesswork.

Of course we're just having fun. Everyone knows the best way is this:

print shift @{[(split//,$num)[0-(@{[split//,$num]})]]}

In reply to Re^3: How to extract the first elemnet from an integer type value ??? by davido
in thread How to extract the first elemnet from an integer type value ??? by sanjay nayak

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.