Konrad Foerstner wrote:
Hi folks,an new question about the mystery of regexs: I want to store some parts of a file wich are separetet by "#". Each each part should become an entry of an array. example: " # foobar nothing important nothing interesting # bar foot lululul lalala lalala # foobar2 Rumba-Samba-Tango " (okay it stop before the example becomes to silly :) )
To late. ;-)
Your use of the range won't work in this context, because you only have access to 1 line. How aobut something like:$array[0] should contain: " # foobar nothing important nothing interesting " Well, my code looks like this: open(INPUT,$input_file); while (<INPUT>) { if (/#/ .. /\n#/) { push @array, $_; } }
while (<INPUT>) {
if (/^#/) {
# start new array element
push @array, $_;
}
else {
# append to last array element
$array[$#array] .= $_;
}
}
--Untested--
The other option would be to slurp the file into a single string by nulling the record separator and then splitting on #, but that breaks down for large files and if a particular entry can contain a #, but I assume not since you weren't explicitly looking for # at the beginning of a line (^) or should you have been?
HTH,
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]