i want create hash table data in file.
the file contains bunch of commands written as
===|showcommand|
every time see delimiter want create hash key , store data below array in value until sees next delimiter.
the next delimiter same thing create hash key delimiter name , store data on next lines following array value.
my %commands; $name; $body; while (<>) { if (my ($new_name) = /===\|([^|]*)\|/) { $commands{$name} = $body if defined($name); $name = $new_name; $body = ''; } else { $body .= $_; } } $commands{$name} = $body if defined($name);
assumes body of command starts on line after header, , stop on line before 1 next header.
Comments
Post a Comment