[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] chunk 27 error ???



At 11:51 am 24/8/96, Dave Shaffer wrote:
>>I got this error:
>
>>     <snip>
>>          # Could not open  TOC.HTM.
>>         File '...'; Line 272 # <THEFILE> chunk 27        <---
>>         :/CIVILWAR/LIBCONG/ TOC.HTM
>>      </snip>
>

        [ ... snip ... ]

>After investigating this a little futher, I found that the filename
>that caused this error had a space in front of it...
>The filename is valid under the mac OS. Is this a MacPerl bug???

No. It's a Perl feature. If you look on page 165 of the Camel book, you'll
see a discussion of this. Leading and trailing whitespace in filenames gets
stripped before it's passed to 'open', so that 'open' tries to open
'TOC.HTM' rather than ' TOC.HTM', fails to find it, and you get an error.

I don't fully understand the significance of 'chunk', but I think it's
Perl's way of trying to tell you where the error happened. Perhaps because
input isn't necessarily line-bounded, Perl prefers to talk to 'chunks'
rather than 'lines'. Unless you've changed '$/', chunks are probably
exactly equivalent to lines, so that would mean your error occurs at line
27 in whatever input file is being read through THEFILE.

Getting back to your filename problem, Schwartz and Wall recommend:

        $file =~ s#^\s#./$&#;
        open(FOO, "< $file\0");

What this does is to turn ' foo' into './ foo', which - on UNIX at least -
is strictly equivalent, but doesn't contain leading whitespace (the '\0' in
the 'open' command protects trailing whitespace). On a Macintosh, the form:

        $file =~ s#^\s#:$&#;

appears to do the desired thing.

                                        A

--
angus@aegypt.demon.co.uk  angus@pobox.com  http://www.tardis.ed.ac.uk/~angus/

 "I am here by the will of the people ... and I will     "Metrophage"
  not leave until I get my raincoat back."              Richard Kadrey