Link to home
Create AccountLog in
Avatar of sreeman78
sreeman78

asked on

Pattern match

Hi,

        I want to grep the value presnt inside <sql type="cognos">  XXXXX</sql>
in the attached file there are 98 occurences .
I want to grep this value (XXXXX) and push it inside an array .So that that array would contain all the XXXXX .I am attaching the file <model.xml>
my code
my $infile = shift;
open INFILE, "<", $infile;
$count=0;


while ($in = <INFILE>) {
    #print if (/<dataSourceRef>.*<\/dataSourceRef>/);
      
($input) = $in =~ (/<sql type="cognos">(.*?)<\/sql>/);
push @array,$input;
      
}      

close INFILE;
print scalar @array ;
print join ("\n","@array\n");

 model.xml
Avatar of Carl Bohman
Carl Bohman
Flag of United States of America image

Your match is not working because .* does not match across line breaks (as exist in your file).  If I were you, I would change (.*?) to ([^<]*) in order to match everything up to the end tag: </sql>.  This will match across line breaks.  The other option is to add the "s" modifier after the last slash as in:
($input) = $in =~ (/<sql type="cognos">(.*?)<\/sql>/s);
ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.