Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

In a piece of code that I'm working on, I've got some report data that consists of a scalar that contains data about tags in a document and what line the tags are on. The data is organized so that there is a line number, followed by a colon, then the report data which can span multiple lines. What I'm trying to do is split the data up so that I've got a hash with the line numbers as the keys and the data as the values. The problem that I'm running into is when the data for a line number spans multiple lines ("\n" delimited). I'm attempting to use a while loop and regex to split the data up, but it's not exactly working right. Any help would be greatly appreciated...

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $info; $info .= $_ while(<DATA>); my %lines; while($info =~ m/(\d+)\: (.+?)/gms) { $lines{$1} = $2; } print Dumper (%lines); __DATA__ 3: Tag <test> found Tag <test> found 5: Tag <test> found 7: Tag <test> found 14: Tag <test> found 16: Tag <test> found 18: Tag <test> found 21: Tag <test> found 25: Tag <test> found 27: Tag <test> found 29: Tag <test> found 32: Tag <test> found 34: Tag <test> found 49: Tag <test> found 80: Tag <test> found 98: Tag <test> found Tag <test> found


In reply to Matching over multiple lines in a scalar by Rich36

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2021-05-13 21:52 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (144 votes). Check out past polls.