in reply to parse file per customized separator / block / metadata
Works as follows:#!/usr/bin/perl use strict; use warnings; my($first_line,%records,$sep); chomp($first_line =readline (DATA)); seek (DATA,462,0);# use seek(FILEHANDLE,0,0) to return to start of fil +e. print "Please enter the seperator example line follows,:\n\t\"$first_l +ine\"\n"; chomp($sep=<STDIN>); while(<DATA>){ my @record=split/\Q$sep\E/,$_; $records{$record[0]}=$record[1]; } for my $name (sort(keys %records)){ print "$name has the value $records{$name}\n"; } __DATA__ name :-$& value anim :-$& freagra nomme :-$& valeur
~/tmp$ perl tmp.pl Please enter the seperator example line follows,: "name :-$& value" :-$& anim has the value freagra name has the value value nomme has the value valeur
|
|---|