You're using capturing parentheses, which will cause the capture to be inserted into the split result (read perldoc split on this). Also, please use strict and use warnings, those would have caught a typo in $chunck1 as well as your incorrect use of the variable name $sectionname2 (where you actually mean $chunk2. Below a corrected version of your script
#!/usr/bin/perl use strict; use warnings; my $chunk1; my $chunk2; my $chunk3; { local $/ = undef; (undef,$chunk1,$chunk2,$chunk3) = split(/^!(?:sectionname1|section +name2|sectionname3)$/m, <DATA>); } print $chunk2; __DATA__ !sectionname1 this is the data !sectionname2 this is more data !sectionname3 end
In reply to Re: Howto separate one file into three and refer to each of these three chuncks later on
by tirwhan
in thread Howto separate one file into three and refer to each of these three chuncks later on
by benoitl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |