Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Adjusted for your latest data.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11144249 use warnings; open my $fh, '<', \<<END; # FIXME with normal open Property job 1 : Activity coefficients ln(gamma) ; Settings job 1 : T= 298.15 K ; x(6)= 1.0000 ; Units job 1 : Concentrations x : mole fraction ; Nr Compound ln(gamma) 1 F002 4.66656083 2 F011 26.13597035 3 F101 32.47411476 4 F11-1 29.58963453 5 F111 30.24092207 6 h2o 0.00000000 7 acetonitrile 2.14102090 8 chlorobenzene 8.72282917 9 chcl3 6.98143674 10 cyclohexane 10.20251798 11 1,2-dichloroethane 6.32324557 12 ch2cl2 5.50767091 13 1,2-dimethoxyethane 2.56706253 14 n,n-dimethylacetamide -1.64673734 Property job 2 : Activity coefficients ln(gamma) ; Settings job 2 : T= 298.15 K ; x(7)= 1.0000 ; Units job 2 : Concentrations x : mole fraction ; Nr Compound ln(gamma) 1 F002 1.69945785 2 F011 0.74578421 3 F101 2.67268035 4 F11-1 1.64808218 5 F111 1.95840198 6 h2o 2.08530828 7 acetonitrile 0.00000000 8 chlorobenzene 1.08379112 9 chcl3 0.46576330 10 cyclohexane 3.71606919 11 1,2-dichloroethane -0.02354847 12 ch2cl2 -0.23798262 13 1,2-dimethoxyethane 1.22044280 14 n,n-dimethylacetamide 0.44524110 END local $_ = do{ local $/; <$fh> }; # slurp entire file my %solvent_face; $solvent_face{ "$3_$1" } = $2 while /\b (F\S+) \h+ ([-\d.]+) (?=.*? (\S+) \h+ 0.00000000 )/gsx; use Data::Dump 'dd'; dd \%solvent_face;

Outputs:

{ "acetonitrile_F002" => 1.69945785, "acetonitrile_F011" => 0.74578421, "acetonitrile_F101" => 2.67268035, "acetonitrile_F11-1" => 1.64808218, "acetonitrile_F111" => 1.95840198, "h2o_F002" => 4.66656083, "h2o_F011" => 26.13597035, "h2o_F101" => 32.47411476, "h2o_F11-1" => 29.58963453, "h2o_F111" => 30.24092207, }

Correct ?


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":



  • 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 browsing the Monastery: (3)
As of 2024-04-19 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found