in reply to Re: Reading structured records from a file
in thread Reading structured records from a file

I was thinking just the same as you. But there's some tiny bugs. First, it should be @rec{@keys}. No scalar sigil. Second, having another delimiter than / in a regex often mean that you might forget a trailing delimiter if the last char in the pattern is a slash. That's the case here. You forgot the last colon.

It could also be worth to mention the special behaviour for $/ = "".

Replies are listed 'Best First'.
Re(3): Reading structured records from a file
by dmmiller2k (Chaplain) on Jan 20, 2002 at 00:45 UTC

    Whoops!

    Thanks for pointing out those silly errors. You are right about @rec{@keys} -- I actually spotted and corrected that after submitting it for the first time, but I got distracted by something (I was at work) and evidently closed the browser before submitting it again. Ditto the trailing colon in the one-liner.

    Appreciate the catch, however.

    From perlvar:

    input_record_separator HANDLE EXPR
    $INPUT_RECORD_SEPARATOR
    $RS
    $/

    The input record separator, newline by default. Works like awk's RS variable, including treating empty lines as delimiters if set to the null string. (Note: An empty line cannot contain any spaces or tabs.) You may set it to a multi-character string to match a multi-character delimiter, or to undef to read to end of file. Note that setting it to "\n\n" means something slightly different than setting it to "", if the file contains consecutive empty lines. Setting it to "" will treat two or more consecutive empty lines as a single empty line. Setting it to "\n\n" will blindly assume that the next input character belongs to the next paragraph, even if it's a newline. (Mnemonic: / is used to delimit line boundaries when quoting poetry.)

    Update: emphasis added.

    dmm