Perl: Separator

Hello all,

I'm trying to break down a file with the following format:

[section_nme]
entries
dzdf
daff

[section 2]
enries
dfln
fnljfd
.
.
..
.

I'm reading this file, using "[" as my separator. It's working quite well, but I would like to be able to read the "[" character into my array as a valid character as well. So I'm wondering - is it possible to set a "just before" tag as my separator ($/)??

Thanks.

As far as I know it is not possible. $/ is just a simple string, you can't try and define a pattern like you might be able to do with other shells scripts. But you can add the '[' as needed to the output after getting it from the file.

don't use $/

try reading whole thing as a string, use split to get whwat you need instead

$/ is for cutting streams. It isn't even a string until you place it into a register.
or use it to slurp the whole file into a variable.

Example

open (FILE, "$filename");
local $/;
$file=<FILE>;
close(FILE);

#the entire file is in one variable including the [
@file=split("[", $file);
#now it is in an array.

I am pretty sure that is going to do the exact same thing he is already doing.

You may want to adopt a different approach in lieu of splitting -

$
$ cat data.txt
[section_nme]
entries
dzdf
daff

[section 2]
enries
dfln
fnljfd

[section 3]
entry_1
entry_2
entry_3

$ 
$ perl -ne 'BEGIN{$/=""}{while (/(\[.*)/sg) {print ">>",$1}}' data.txt
>>[section_nme]
entries
dzdf
daff

>>[section 2]
enries
dfln
fnljfd

>>[section 3]
entry_1
entry_2
entry_3

$
$

tyler_durden