A simple code snippet
#!/usr/bin/perl -w use strict; use warnings; use constant HANDLER => { 'line something starts here {' => sub{ return "Handler 1: do s +omethig with this data\n".shift;}, 'next block of something starts here {' => sub{ return "Handle +r 2: do somethig with this data\n".shift;}, # Other record Handlers }; # Read Records while (my $line = <DATA>){ chomp $line; next unless $line =~ /{/; my $header = $line; # READ HEADER # READ BODY $/="ends here }\n"; my $body = <DATA>; chomp $body; $/="\n"; print "Get Handler for: [$header]\n"; my $output = &{HANDLER->{"$header"}}($body); print $output if $output; } __DATA__ line something starts here { contains line 1 contains line 2 contains line 3 contains line 4 ends here } next block of something starts here { contains line 1 contains line 2 contains line 3 contains line 4 ends here }
In reply to Re: Replacing, cutting, deleting lines in the file
by gulden
in thread Replacing, cutting, deleting lines in the file
by Jarek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |