in reply to extracting strings from text file
#!perl use strict; use warnings; use Data::Dump qw/pp dd/; my %hash; local $/="(Special)"; while(<DATA>){ if ($_ =~ /TG:\s(VIN:\d+)\ntype:\s(.+)\n/){ my $keys = $1; my $values = $2; $hash{$keys} = $values; } } pp \%hash; __DATA__ (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..
{ "VIN:1000000" => "a very special type of plane", "VIN:1000001" => "a very special type of car", "VIN:1000002" => "a very special type of boat", }
> What could be the problem here?
You? ;-)
seriously I think your input is different from what you've shown us. probably check it bytes wise, especially line-endings.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|