in reply to Howto separate one file into three and refer to each of these three chuncks later on

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

All dogma is stupid.
  • Comment on Re: Howto separate one file into three and refer to each of these three chuncks later on
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Howto separate one file into three and refer to each of these three chuncks later on
by benoitl (Initiate) on Jun 27, 2007 at 16:46 UTC
    Thanks so much it works now !