in reply to Re: How to extract the first elemnet from an integer type value ???
in thread How to extract the first elemnet from an integer type value ???

my $num = 100; my $digit = int ($num / 10 ** (length($num)-1) );
--
Leviathan
  • Comment on Re^2: How to extract the first elemnet from an integer type value ???
  • Download Code

Replies are listed 'Best First'.
Re^3: How to extract the first elemnet from an integer type value ???
by GrandFather (Saint) on Aug 31, 2006 at 09:55 UTC
    my $num = 100; my $digit = int ($num / ('1' . ('0' x int (length ($num) -1))));

    DWIM is Perl's answer to Gödel
      my $digit = chop ( my $mun = reverse $num );
        chop $num while $num > 9;

        DWIM is Perl's answer to Gödel

      Okay :)

      my $num = 100; my $digit = int ($num / ('1' . ('0' x (@{[ $num =~ /(.)/g ]} - 1))));

      I don't know.. is this reverse golf?

      --
      Leviathan