Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Applying regex to each line in a record.

by choroba (Archbishop)
on Oct 24, 2020 at 19:30 UTC ( #11123130=note: print w/replies, xml ) Need Help??


in reply to Applying regex to each line in a record.

You need to remember the current header (or the current section).
#!/usr/bin/perl use warnings; use strict; my %hash; my $header; while (<>) { if (my ($h) = /^(.*):$/) { $header = $h; } elsif (my ($k, $v) = /^(.*):(.*)$/) { $hash{$header}{$k} = $v; } } use Data::Dumper; print Dumper \%hash;
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123130]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-09-20 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?