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??
$key       => { map { split m{\s*=\s*} } @record }

Try that with values containing "=". Like this:

[CELL_NAME1] COMMENT = "Perl parsing = oh no" FIRST = "TEST1" SECOND = "ID1" THIRD = 123 FOURTH = "THREE" FIFTH = 12345 SIXTH = 6789 SEVENTH = QWERTY [CELL_NAME2] COMMENT = "Tester" FIRST = "TEST2" SECOND = "ID2" THIRD = 1234 FOURTH = "FOUR = bad" FIFTH = 12345 SIXTH = BOARD SEVENTH = MOUSE [CELL_NAME3] COMMENT = "Parser" FIRST = "TEST3" SECOND = "ID3 = and how = did this = happen?" THIRD = 12345 FOURTH = "FIVE" FIFTH = 12345 SIXTH = PAD SEVENTH = KEY EOF

Did you expect that?

>perl 1179657.pl Odd number of elements in anonymous hash at 1179657.pl line 45, <$inFH +> chunk 3. Odd number of elements in anonymous hash at 1179657.pl line 45, <$inFH +> chunk 3. Odd number of elements in anonymous hash at 1179657.pl line 45, <$inFH +> chunk 3. %HoH = ( 'CELL_NAME1' => { '"ID1"' => 'THIRD', '"TEST1"' => 'SECOND', '"THREE"' => 'FIFTH', '123' => 'FOURTH', '12345' => 'SIXTH', '6789' => 'SEVENTH', 'COMMENT' => '"Perl parsing', 'QWERTY' => undef, 'oh no"' => 'FIRST' }, 'CELL_NAME2' => { '12345' => 'SIXTH', 'BOARD' => 'SEVENTH', 'COMMENT' => '"Tester"', 'FIRST' => '"TEST2"', 'FOURTH' => '"FOUR', 'MOUSE' => undef, 'SECOND' => '"ID2"', 'THIRD' => '1234', 'bad"' => 'FIFTH' }, 'CELL_NAME3' => { '"FIVE"' => 'FIFTH', '12345' => 'SIXTH', 'COMMENT' => '"Parser"', 'FIRST' => '"TEST3"', 'KEY' => undef, 'PAD' => 'SEVENTH', 'SECOND' => '"ID3', 'and how' => 'did this', 'happen?"' => 'THIRD' } ); >

Hint: split accepts THREE arguments.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^8: Parse a file and store it in hash of hashes by afoken
in thread Parse a file and store it in hash of hashes by Sonali

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.