in reply to extracting strings from text file
#!/usr/bin/perl # https://perlmonks.org/?node_id=1221960 use strict; use warnings; use Data::Dumper; open my $fh, '<', \<<END; # fake file for testing purposes (Special) TG: VIN:1000000 type: a very special type of plane (Special) TG: VIN:1000001 type: a very special type of car (Special) TG: VIN:1000002 type: a very special type of boat this repeats many times.. END my %hash = do{local $/; <$fh>} =~ /^TG:\s(VIN:\d+)\ntype:\s(.*)/gm; print Dumper \%hash;
Outputs:
$VAR1 = { 'VIN:1000001' => 'a very special type of car', 'VIN:1000002' => 'a very special type of boat', 'VIN:1000000' => 'a very special type of plane' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: extracting strings from text file
by GrandFather (Saint) on Sep 09, 2018 at 21:18 UTC |