I have a file ~/bigfile.txt that consists of thousands of blocks of text of the formBLOCK NUMBER : <block>SIZE : <size1> <size2>EXTRA : <extraNumber><block of text>For this example say$ cat ~/bigfile.txtBLOCK NUMBER : 1SIZE : 7 6EXTRA : 0john paulgeorge ringoBLOCK NUMBER : 2SIZE : 7 3EXTRA : -10i amthewalrusBLOCK NUMBER : 3SIZE : 4 3EXTRA : -1024hello worldI am trying to write a script that separates each block into a separate file named <block>-block.txt, nested into subdirectories of ~/data/ indexed by <size1> and <size2>. For instance, running the script should result in $ tree ~/data/~/data/|- 4-size1   |- 3-size2      |- 3-block.txt|- 7-size1   |- 3-size2      |- 2-block.txt   |- 6-size2      |- 1-block.txtCurrently I have a script that simply dumps each block to a separate file in ~/data/ but I can't figure out how to alter it. I can post my current script if that would help but I suspect that it's quite inefficient and not suited to tackle this sort of organizational task.I would appreciate any pointers on how to accomplish this task with perl.
How can I make a perl script parse blocks more intelligently?
perl
I would write:perl -MFile::Path=make_path -00 -ne '    ($block) = /BLOCK NUMBER : (\d+)/;     @sizes = /SIZE : (\d+) (\d+)/;     $dir = sprintf data/%d-size1/%d-size2, @sizes;    make_path $dir;    if (open $fh, >, $dir/$block-block.txt) {        print $fh $_;        close $fh;    }' bigfile.txt 