Here's a couple of different choices inspired by LanX's Re: Help with parsing a file (hash keys are unique)

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11144249 use warnings; my $file = 'data.11144249'; open my $fh, '<', $file or die "$! opening $file"; local $_ = do{ local $/; <$fh> }; # slurp entire file my %solvent_face; # as requested $solvent_face{ "$3_$1" } = $2 while /\b (F\S+) \h+ ([-\d.]+) (?=.*? (\S+) \h+ 0.00000000 )/gsx; # by solvent, then arrays of each F*** push @{ $solvent_face{ $3 }{ $1 } }, $2 while /\b (F\S+) \h+ ([-\d.]+) (?=.*? (\S+) \h+ 0.00000000 )/gsx; # by F***, then arrays of solvent push @{ $solvent_face{ $1 }{ $3 } }, $2 while /\b (F\S+) \h+ ([-\d.]+) (?=.*? (\S+) \h+ 0.00000000 )/gsx; use Data::Dump 'dd'; dd \%solvent_face;

Outputs:

{ "acetonitrile" => { "F002" => [1.69945785], "F011" => [0.74578421], "F101" => [2.67268035], "F11-1" => [1.64808218], "F111" => [1.95840198], }, "acetonitrile_F002" => 1.69945785, "acetonitrile_F011" => 0.74578421, "acetonitrile_F101" => 2.67268035, "acetonitrile_F11-1" => 1.64808218, "acetonitrile_F111" => 1.95840198, "F002" => { acetonitrile => [1.69945785], h2o => [4.66656083] }, "F011" => { acetonitrile => [0.74578421], h2o => [26.13597035] }, "F101" => { acetonitrile => [2.67268035], h2o => [32.47411476] }, "F11-1" => { acetonitrile => [1.64808218], h2o => [29.58963453] }, "F111" => { acetonitrile => [1.95840198], h2o => [30.24092207] }, "h2o" => { "F002" => [4.66656083], "F011" => [26.13597035], "F101" => [32.47411476], "F11-1" => [29.58963453], "F111" => [30.24092207], }, "h2o_F002" => 4.66656083, "h2o_F011" => 26.13597035, "h2o_F101" => 32.47411476, "h2o_F11-1" => 29.58963453, "h2o_F111" => 30.24092207, }

In reply to Re: Help with parsing a file by tybalt89
in thread Help with parsing a file by Odar

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.