in reply to Regexp and reading a file n-lines at time
This would work, You'll get hash of arrays
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $HASH; my $Title; while ( <DATA> ) { chomp; next if ! $_; if ( /^\d+\.(.*)/sg ) { $Title = $1; $HASH->{$Title} = []; next; } if ( exists $HASH->{$Title} ) { push @{$HASH->{$Title}} , $_; } } print Dumper($HASH); __DATA__ 1.TITLE OF FIRST RECIPE abstract Recipe 1. Recipe 2. Recipe ... Procedure... 2.TITLE OF SECOND RECIPE ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regexp and reading a file n-lines at time
by jwkrahn (Abbot) on Feb 01, 2010 at 15:42 UTC | |
|
Re^2: Regexp and reading a file n-lines at time
by epimenidecretese (Acolyte) on Feb 01, 2010 at 13:32 UTC | |
|
Re^2: Regexp and reading a file n-lines at time
by epimenidecretese (Acolyte) on Feb 03, 2010 at 10:13 UTC | |
by epimenidecretese (Acolyte) on Feb 03, 2010 at 14:22 UTC | |
by hbm (Hermit) on Feb 03, 2010 at 18:24 UTC |