green_lakers has asked for the wisdom of the Perl Monks concerning the following question:


Hi there,

I have an array which looks like this:-
array[0]=pppp_mmmm   (install)   111111.156558  1111   918( 43%)   833( 39%)    85(  4%)
I want to extract this number 156558 and put it in a variable abc

output abc = 156558
Hi Everyone,
The first element of the array is :---
pppp_mmmm (install) 111111.156558 1111 918( 43%) 833( 39%) + 85( 4%)

I want the value of the variable abc = 156558

Replies are listed 'Best First'.
Re: Finding an element of an array
by ikegami (Patriarch) on Dec 04, 2008 at 21:02 UTC
    That's one array element, so this has nothing to do with arrays. You could use a regular expression. For example, the following code extracts all the digits that immediately follow the first ".":
    my ($abc) = $array[0] =~ /\.(\d+)/;
Re: Finding an element of an array
by Limbic~Region (Chancellor) on Dec 04, 2008 at 21:07 UTC
Re: Finding an element of an array
by Lawliet (Curate) on Dec 04, 2008 at 21:04 UTC
    I want to extract this number 156558 and put it in a variable abc

    Then what are you waiting for? :P

    A question for you ~ is array[0]=pppp_mmmm the 0th element of the array or are you trying to assign that whole string to the 0th element?

    Update OPer updated his OP. -- If there will only be one period in the string than the regex that has been stated earlier will suffice. Could we get more sample data? (I assume that that is sample data and there are other strings that you need to retrieve information from.)

    I'm so adjective, I verb nouns!

    chomp; # nom nom nom