http://www.perlmonks.org?node_id=89934


in reply to changing DB delimiters

You can choose them yourself. See perlvar.

local $/ = "vroom"; #$/ is input separator. From now on, # script will split lines on 'vroom' local $, = "PM!PM!" #$, is print rec separator. From now on, # script will print 'PM!PM!' between items of arr +ay
Jeroen
"We are not alone"(FZ)

Replies are listed 'Best First'.
Re: changing DB delimiters
by Abigail (Deacon) on Jun 20, 2001 at 20:35 UTC
    Actually, $, would be the field separator, while $\ is the record separator. If you want it to work for the given code, you'd need to do:
    local $/ = local $\ = local $, = "\n";
    or else the last record isn't properly terminated.

    -- Abigail

      Well, it depends on what you do, actually. I understand that he prints his 'DB' with print @guests. In that case, you need to separate the fields with $,. The $\ is active after each print statement, as appears from:
      $OUTPUT_FIELD_SEPARATOR
      $OFS
      $,
      The output field separator for the print operator. Ordinarily the print operator simply prints out its arguments without further adornment. To get behavior more like awk, set this variable as you would set awk's OFS variable to specify what is printed between fields. (Mnemonic: what is printed when there is a "," in your print statement.)

      $OUTPUT_RECORD_SEPARATOR
      $ORS
      $\
      The output record separator for the print operator. Ordinarily the print operator simply prints out its arguments as is, with no trailing newline or other end-of-record string added. To get behavior more like awk, set this variable as you would set awk's ORS variable to specify what is printed at the end of the print. (Mnemonic: you set `$\' instead of adding "\n" at the end of the print. Also, it's just like `$/', but it's what you get "back" from Perl.)
      So it makes no sense to set $, and $\ to the same value.

      Jeroen

        So it makes no sense to set $, and $\ to the same value.

        Actually, it does. It makes no sense to not set it to the same value, unless you take care of those things elsewhere. Remember that all the records are collected in a single array, and there's only one print statement, printing out the entire database. Not setting $\ equal to $, makes that your last record has a different format than the others.

        -- Abigail