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

my $digit = (split //, '100')[0];

Update or

my $num = 100; my $digit = int ($num / 10 ** int (log ($num) / log(10)));

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: How to extract the first elemnet from an integer type value ???
by Leviathan (Scribe) on Aug 31, 2006 at 09:49 UTC
    my $num = 100; my $digit = int ($num / 10 ** (length($num)-1) );
    --
    Leviathan
      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 );

        Okay :)

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

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

        --
        Leviathan