Re: [MacPerl-WebCGI] well split!! (Solved)
[email protected] Thu, 8 Mar 2001 14:58:16 -0500
| Newsgroups | perl.macperl.webcgi |
|---|---|
| Message-ID | <p05010405b6cd9114fd51@[64.194.142.225]> |
-Bruce:
>... I'm not clear about the evolution to why you are explicitly
>setting the EOR in your data file, but if that's worth preserving,
>then setting $/ before reading the file with the <> input operator
>is fine.
I am explicitly setting the EOR in my data files because I think that
is the way to do a field <tab> record <ret> delimited file. In doing
so, I had no idea of the diversity of what constitutes a simple EOR.
Back in the old Apple ][ days, I had to specifically set a character
aside to determine the EOF of files as well as determining
delimitation between fields and records. So, it's a force of habit to
think in those terms -- plus the data files I will be using in this
cgi will be generated by a spreadsheet which has an output common to
what I used in this investigation.
>What makes it safe is the localizing. $/ is by default Perl's \n,
>which within a Perl program means "End of Line/Record in the current
>OS", as others have pointed out. So, if you change it to \r match
>your data, you need to make sure to change it back, just in case
>your script needs to read some other file later that happens to be
>in the format native to the OS.
>
>Notice the outermost '{' and '}' in the example I gave before:
>
> {
>local $/ = "\r";
>while (<DATA>) {
> # ...
> }
> }
>
>Using
>
> local $/ = "\r";
>
>within a block ensures that $/ goes back to whatever value it had
>before you changed it to \r. Then you don't have to worry about $/
>anymore, especially when you go to modify the script next year... I
>would also put a note with the line altering $/, reminding me that
>I'm doing that to match the input data
>
> {
> # match incoming data
> local $/ = "\r";
> while (<DATA>) {
> # ...
Wow, nice feature with limiting the scope of this function/statement
to the block.
>-snip-
>This way, you have control over your EOR throughout your process.
Another nice tip -- thanks.
>OTOH, remember that if you let Perl use its defaults, the EOR
>manipulations usually "drop out of both sides of the equation."
I'll have to think about that. If perl generates the data file, then
I would expect that to be correct. However, if another program
generates the file, then it's up to the OS, I guess.
Many thanks for your time and most informed help.
tedd
--
http://sperling.com/