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
Perl

Avatar of undefined
Last Comment
Suhas .
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Suhas .
Suhas .
Flag of United States of America image

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Perl
Perl

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects. Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.

26K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo