Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Thanks Phil for useful advice. BTW I created 3 subroutines that cover most of cases in Text::Balanced What do you think ?
###################################################################### +####### #Input file Looks Like: #SingleLinesMultiLineFile #START_TAG\ value1 \END_TAG #SomeChar #START_TAG\ value2 \END_TAG #SomeChar #START_TAG\ value3 \END_TAG #SomeChar #end SingleLinesMultiLineFile #Usage: #$InputFile="$LocationOfTheScriptsDirectory\\MultiLine.txt"; #$StartTag='START_TAG\\'; #$EndTag='\END_TAG'; #@AValues=getInfoFromSingleLinesMultiLineFile($InputFile,$StartTag,$En +dTag); #Result:@AValues=qw(value1 value2 value3); sub getInfoFromSingleLinesMultiLineFile { my ($InputFile,$StartTag,$EndTag)=@_; my ($line,@wanted_substrings); #Openning file for reading open(IFH,"$InputFile") || die "Can't open file: $InputFile\n"; while($line=<IFH>) { if($line =~ /\Q$StartTag\E(.*?)\Q$EndTag\E/) { push(@wanted_substrings,$1); } } return @wanted_substrings; } ###################################################################### +####### #Input file Looks Like: #MultipleLinesMultiLineFile #SomeChar # START #value # END #AnotherChar #end MultipleLinesMultiLineFile # #Usage: #$InputFile="$LocationOfTheScriptsDirectory\\MultyLine.txt"; #$StartTag='START'; #$EndTag='END'; #@StartEnd=getInfoFromMultipleLineMultiLineFile($InputFile,$StartTag,$ +EndTag); sub getInfoFromMultipleLinesMultiLineFile { my ($InputFile,$StartTag,$EndTag)=@_; my ($line,@wanted_substrings); #Openning file for reading open(IFH,"$InputFile") || die "Can't open file: $InputFile\n"; while($line=<IFH>) { if (($line =~ m/\Q$StartTag\E/) .. ($line =~ m/\Q$EndTag\E/)) { push(@wanted_substrings,$line); } } return @wanted_substrings; } ###################################################################### +####### #Input file for longline: #SingleLineSingleLineFile<A>AAA</A><B>BBB</B><C>CCC</C><A>123</A><D>DD +D</D><A>HHH</A><C>CCC</C>end SingleLineSingleLineFile #Usage: #$InputFile="$LocationOfTheScriptsDirectory\\LongLine.txt"; #$StartTag='<A>'; #$EndTag='<\A>'; #@AValues=getInfoFromSingleLineSingleLineFile($InputFile,$StartTag,$En +dTag); #Result:@AValues=qw(AAA 123 HHH); sub getInfoFromSingleLineSingleLineFile { #Openning file for reading my ($InputFile,$StartTag,$EndTag)=@_; my ($line,@wanted_substrings); open(IFH,"$InputFile") || die "Can't open file: $InputFile\n"; $line = <IFH>; #1 #my @wanted_substrings = $line =~ /<A>(.*?)<\/A>/g; #2 #push(@wanted_substrings,$1) while $line =~ /<A>(.*?)<\/A>/g; #3 while ($line =~ /\Q$StartTag\E(.*?)\Q$EndTag\E/g) { push(@wanted_substrings,$1); } return "@wanted_substrings"; }

In reply to Re^3: Regular Expression problem when Extracting Start\ VALUE \End by gasho
in thread Regular Expression problem when Extracting Start\ VALUE \End by gasho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found