in reply to Help with parsing a file

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11144249 use warnings; open my $fh, '<', \<<END; # FIXME with normal open F001 1.2 F101 3.2 solvent1 0 solvent2 3 three lines of text that are not important and can be skipped F001 2.2 F101 7.2 solvent1 5 solvent2 0 END local $_ = do{ local $/; <$fh> }; # slurp entire file my %solvent_face; $solvent_face{ "$3_$1" } = $2 while /\b (F\w+) \h+ ([\d.]+) (?=.*? ^ (\S+) \h+ 0 \h* \n )/gmsx; use Data::Dump 'dd'; dd \%solvent_face;

Replies are listed 'Best First'.
Re^2: Help with parsing a file
by Odar (Novice) on May 29, 2022 at 18:10 UTC

    Thank you for your help tybalt89. I think your solution prints out (adds to the hash) only the two records for solvent1 from the first (top) block.Still very useful as I learn a lot.

      Nope, does all F***

      Outputs:

      { solvent1_F001 => 1.2, solvent1_F101 => 3.2, solvent2_F001 => 2.2, solvent2_F101 => 7.2, }