On Mon, Nov 23, 2009 at 4:27 AM, shadow52 <ras.collec...@gmail.com> wrote:

> Hey everyone,
>
> I am trying to get just the last 3 numbers from the following number
> from perl using regexs but I have not had no success so I was hoping
> that I could get a little help on this. I just ordered the regex book
> from oreilly so that hopefully in the future I will not have to ask a
> question like this again.
>
> The number is 0000000000000111
>
> I was just wanting to get the last 3 digits from this number to be
> able to get an exact word phrase from my already loaded Hash table
> that I have created for various numbers that I will get the last 3
> numbers from. Oh yeah all I was doing was putting this number in a
> file and then passing it to perl on the command line incase that is
> needed.
>
> Any help is much appreciated or if you can just point me to a good
> place to get a better understanding of how to do this while I wait for
> my book to arrive.
>
> Thanks,
> shadow52
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>
Hi shadow52,

The trick with subsrt works of course and there is no need to set this as
character as this is perl where we don't care what is in the scalar (number,
character or string), the programming language deals with that for us so we
just need to be concerned with the interesting things like how do we do this
in a different way...

With a regular expression you can use the $ to signify the end of the string
so a regulat expression catching the following:
$your_long_number =~ /.*(\d{3})$/;
print "My 3 digits are: $1\n";

Just saw Shawn's solution which I assume will work as well though I am not
sure what the \z is for looking that up :-)

Regards,

Rob

Reply via email to