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

Hi Monks!
I have an xml file where I am trying to read the number located between <customer_id> and </customer_id>. I can't use substr beause the position will not be consistent. I was thinking of split but after doing some research I am not sure it will be possible with it. I was then looking into a regrex exp but i am not too proficient in it and somewhat lost. The length of the number will be consistent though (7).
Could you please help me figure out how I could extract the number between the above mentioned tabs?
eg. <customer_id>1234567</customer_id> how to get 1234567?
Thanks in advance!

Thanks for all the input guys! i ended up using the following:

if($_ =~ /<Customer_ID>(.*)<\/Customer_ID>/) { my $c = $1; }

Replies are listed 'Best First'.
Re: Grabbing specific string from a line
by choroba (Cardinal) on Mar 01, 2012 at 18:30 UTC
    XML::LibXML:
    use XML::LibXML; my $xml = XML::LibXML->load_xml( ... ); my $value = $xml->documentElement->getElementsByTagName("customer_id") +->[0]->textContent; print $value, "\n";
Re: Grabbing specific string from a line
by kcott (Archbishop) on Mar 01, 2012 at 18:23 UTC
Re: Grabbing specific string from a line
by JavaFan (Canon) on Mar 01, 2012 at 18:21 UTC
    Untested:
    my ($number) = $str =~ m{<customer_id>([0-9]{7})</customer_id>};
      It will work until someone decides to add some whitespace and linebreaks and then your regex solution doesn't work anymore. Caution is advised!

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics
        Hmmm, is it possible to give a solution for any problem that will still hold if someone modifies the requirement? Considering that it's a given the length of the number is fixed, I wouldn't worry too much about it.

        I'm also assuming the OP isn't a drooling idiot, and has the ability to add \s* to a pattern when required.