On 11/18/05, Brian Volk <[EMAIL PROTECTED]> wrote:
> Hi All~
>
>
>
> I'm trying to get my head around local $/ = ''; #enable paragraph mode.
>
>
>
> If I have a tab delimited file that looks like this:
>
>
>
> 1311001
>
> Aed Motorsports
>
> 5373 W 86th St
>
> Indianapolis, Indiana 46268 U.S.A.
>
>
>
> 7069210
>
> Bird Electronic
>
> 30303 Aurora Rd
>
> Solon, Ohio 44139 U.S.A.
>
>
>
> 1020700
>
> Charis Disk Golf
>
> Ste 160-135
>
> 4000 W 106th St
>
> Carmel, Indiana 46032 U.S.A.
>
>
>
> and code that looks like this:
>
>
>
>     local $/ = '';
>
>     while (<OLD>) {
>
>
>
>     my @rows = split /\n/;
>
>
>
>     print SAVESTDOUT join("\t", @rows), "\n";
>
>
>
>     }
>
>
>
> which produces an output file that looks like this: (exactly what I want)
>
>
>
> 1311001        Aed Motorsports       5373 W 86th St        Indianapolis,
> Indiana 46268 U.S.A.
>
> 7069210        Bird Electronic           30303 Aurora Rd       Solon, Ohio
> 44139 U.S.A.
>
> 1020700        Charis Disk Golf         Ste 160-135             4000 W 106th
> St      Carmel, Indiana 46032 U.S.A.
>
>
>
> I understand that $/ uses a blank line as a record separator

Yes

>but is it
> correct in saying that $_ is being assigned to every line in the original
> file?

No.

> And if so, why is my @rows = split /\n/; only splitting on the blank
> line (record separator) and not after each line in the file?

It is splitting on each newline.

> I guess I
> don't understand the magic that is happening... could someone pls explain
> this in beginners' terms?  :~)

Sure.

Assuming you formatted the data and output correctly when you emailed
the list, it looks like your data isn't what you think it is.  Perhaps
your data is coming from a different operating system, or a program
that uses an OS-specific byte sequence as the "blank line" record
seperator. Either way, it looks as though Perl isn't recognizing your
"blank" lines as a valid match for "\n\n+" (the internal split string
it uses when $/ is set to ''), so it is slurping the entire file,
slitting on the "\n" sequences it sees at the end of lines withint the
records, and then outputting the entire file joined with tabs.  When
the bytes that represent your "blank line" are printed to screen, you
see the double carriage return, but Perl is treating the entire input
and output as a single string.  If you look closely and the output,
you'll probably see a trailing tab at the end of each "record". 
Possibly your file is actually a VMS "record oriented file" or
something similar? Or a C database file with null-terminated strings
that your text editor/pager is interpreting as a blank line?

Tell us a little bit more about where the data is coming from, how
it's being created, and what OS you're on, and we may be able to help
you sort this out.

HTH

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to