Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!
I have a big file that has several text entries in it, which are separated by // in the end, so I have changed the normal delimiter to be $/="//\n"; instead of a simple newline.
Now, I am implementing a pattern match, where, if it is succesful, I need to get the next line within each individual entry.
Normally this would be done by assigning:
if ( pattern match ) { $wanted_line = $_; }
How must I declare this now that I do not have the nornal \n as line separator?

Replies are listed 'Best First'.
Re: Difficulty using $/ as delimiter
by mbethke (Hermit) on Jun 09, 2012 at 17:51 UTC
    If I understand this correctly, you have a file with multi-line records terminated by '//\n'. Like this?
    1 2 3// foo bar baz//
    Then when you change $/ to your record separator, the diamond operator will give you a whole record. And now you need the individual lines within each? I'd say just split on /\n/, but I have a feeling that's not exactly what you wanted. Can you clarify?
Re: Difficulty using $/ as delimiter
by moritz (Cardinal) on Jun 09, 2012 at 17:53 UTC

    It is not clear to me what your actual problem is. If you post some example input, your full code, your actual output and desired output, I can try to help you better.

    That said, if you set $/, then reading from a filehandle via <$fh> or readline, then that value is used as record separator. If you want to extract actual lines from those strings, you can simply split /\n/, $string them.

Re: Difficulty using $/ as delimiter
by ambrus (Abbot) on Jun 09, 2012 at 17:48 UTC

    Uh, the entries you've read still have newlines in them. Just split them like

    @lines_of_this_entry = split /^/;