Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > MacPerl vs. Unix (OS X) Perl

Reply
Thread Tools

MacPerl vs. Unix (OS X) Perl

 
 
Nathan Olson
Guest
Posts: n/a
 
      07-12-2004
Any reason why the following behaves differently from MacPerl to Unix Perl
(in OS 10.2.? (Assume all I want to process is the first file; hence the
@ARGV[0].)



open (THISFILE, @ARGV[0]) || die ("Error opening the file ...");
@contents = <THISFILE>;
close (THISFILE);


In MacPerl, an ordinary text file is parsed into the @contents array with
each paragraph being a element. But in OS X/Unix Perl, the entire contents
of the text file is placed in @contents[0]; in other words, it comes in as a
long string, not as separate elements. Why the difference? Does it have to
do with line-endings? And how can I change this?

Any help will be appreciated.

Nate Olson

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-12-2004
Nathan Olson <(E-Mail Removed)> wrote in
news:BD177587.14163%(E-Mail Removed):

> Any reason why the following behaves differently from MacPerl to Unix
> Perl (in OS 10.2.? (Assume all I want to process is the first file;
> hence the @ARGV[0].)
>
> open (THISFILE, @ARGV[0]) || die ("Error opening the file ...");
> @contents = <THISFILE>;
> close (THISFILE);


It is too late for me to look up what line end character Mac uses right now
but a simple Google search should yield the answer.

OTOH, it looks like you might want to consult the following FAQ:

perldoc -q @array


--
A. Sinan Unur
http://www.velocityreviews.com/forums/(E-Mail Removed)d
(remove '.invalid' and reverse each component for email address)

 
Reply With Quote
 
 
 
 
Jim Keenan
Guest
Posts: n/a
 
      07-12-2004
Nathan Olson <(E-Mail Removed)> wrote in message news:<BD177587.14163%(E-Mail Removed)>...
> Any reason why the following behaves differently from MacPerl to Unix Perl
> (in OS 10.2.? (Assume all I want to process is the first file; hence the
> @ARGV[0].)
>
>
>
> open (THISFILE, @ARGV[0]) || die ("Error opening the file ...");
> @contents = <THISFILE>;
> close (THISFILE);
>
>
> In MacPerl, an ordinary text file is parsed into the @contents array with
> each paragraph being a element.


I don't have MacPerl, so I can't test this statement. But in general
reading a file into an array would result in each *line* -- or, to be
more precise, each *record* -- being a separate element of the array.
The ordinary English meaning of 'paragraph' is a series of lines
separated from another such series by a blank or whitespace-only line.
(See perldoc perlvar on $/.)


> But in OS X/Unix Perl, the entire contents
> of the text file is placed in @contents[0];


Did you mean to say: $contents[0] ??
 
Reply With Quote
 
Iain Chalmers
Guest
Posts: n/a
 
      07-13-2004
In article <Xns95241609DAC50asu1cornelledu@132.236.56.8>,
"A. Sinan Unur" <(E-Mail Removed)> wrote:

> Nathan Olson <(E-Mail Removed)> wrote in
> news:BD177587.14163%(E-Mail Removed):
>
> > Any reason why the following behaves differently from MacPerl to Unix
> > Perl (in OS 10.2.? (Assume all I want to process is the first file;
> > hence the @ARGV[0].)
> >
> > open (THISFILE, @ARGV[0]) || die ("Error opening the file ...");
> > @contents = <THISFILE>;
> > close (THISFILE);

>
> It is too late for me to look up what line end character Mac uses right now
> but a simple Google search should yield the answer.
>
> OTOH, it looks like you might want to consult the following FAQ:
>
> perldoc -q @array


I don't see anything in the original post that suggests a
misunderstanding of arrays... He does indeed have a line ending problem.
He can either change perls understanding of line endings using $\ (see
the input record separator in perldoc perlvar) or change the MacOS9 text
file to a unix text file (and since he's clearly using a Mac, I'll
mentions that BBEdit lets you do this easily).

perldoc perlport has some useful information on this issue:

In most operating systems, lines in files are terminated
by newlines. Just what is used as a newline may vary from
OS to OS. Unix traditionally uses `\012', one type of
DOSish I/O uses `\015\012', and Mac OS uses `\015'.

I notice though, that thats a little out of date these days, perhaps it
should read something like:

In most operating systems, lines in files are terminated
by newlines. Just what is used as a newline may vary from
OS to OS. Unix traditionally uses `\012', one type of
DOSish I/O uses `\015\012', and Mac OS 9 and earlier uses
`\015'. While perl on Mac OS X uses `\012', the OS's
idea of 'text files' varies between `\015' and `\012'.

(as an aside, where's the right place to suggest documentation changes?
here? (as in clpm, not csm) p5p?)

big
--
"I say we take off and nuke the entire site from orbit.
That's the only way to be sure." - Ellen Ripley
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-13-2004
Iain Chalmers <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> In article <Xns95241609DAC50asu1cornelledu@132.236.56.8>,
> "A. Sinan Unur" <(E-Mail Removed)> wrote:
>
>> Nathan Olson <(E-Mail Removed)> wrote in
>> news:BD177587.14163%(E-Mail Removed):
>>
>> > Any reason why the following behaves differently from MacPerl to
>> > Unix Perl (in OS 10.2.? (Assume all I want to process is the
>> > first file; hence the @ARGV[0].)
>> >
>> > open (THISFILE, @ARGV[0]) || die ("Error opening the file ...");
>> > @contents = <THISFILE>;
>> > close (THISFILE);

>>
>> It is too late for me to look up what line end character Mac uses
>> right now but a simple Google search should yield the answer.
>>
>> OTOH, it looks like you might want to consult the following FAQ:
>>
>> perldoc -q @array

>
> I don't see anything in the original post that suggests a
> misunderstanding of arrays...


@ARGV[0]

perldoc -q @array
--
A. Sinan Unur
(E-Mail Removed)d
(remove '.invalid' and reverse each component for email address)

 
Reply With Quote
 
Iain Chalmers
Guest
Posts: n/a
 
      07-13-2004
In article <Xns9525228F3EDAasu1cornelledu@132.236.56.8>,
"A. Sinan Unur" <(E-Mail Removed)> wrote:

> Iain Chalmers <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> > In article <Xns95241609DAC50asu1cornelledu@132.236.56.8>,
> > "A. Sinan Unur" <(E-Mail Removed)> wrote:
> >
> >> Nathan Olson <(E-Mail Removed)> wrote in
> >> news:BD177587.14163%(E-Mail Removed):
> >>
> >> > Any reason why the following behaves differently from MacPerl to
> >> > Unix Perl (in OS 10.2.? (Assume all I want to process is the
> >> > first file; hence the @ARGV[0].)
> >> >
> >> > open (THISFILE, @ARGV[0]) || die ("Error opening the file ...");
> >> > @contents = <THISFILE>;
> >> > close (THISFILE);
> >>
> >> It is too late for me to look up what line end character Mac uses
> >> right now but a simple Google search should yield the answer.
> >>
> >> OTOH, it looks like you might want to consult the following FAQ:
> >>
> >> perldoc -q @array

> >
> > I don't see anything in the original post that suggests a
> > misunderstanding of arrays...

>
> @ARGV[0]
>
> perldoc -q @array


Ahhh, OK, I missed that one... Good catch

big
--
"I say we take off and nuke the entire site from orbit.
That's the only way to be sure." - Ellen Ripley
 
Reply With Quote
 
Bart Lateur
Guest
Posts: n/a
 
      07-13-2004
Tim Hammerquist wrote:

>Mac OS <= 9 used line endings "\x0a\x0a"


Nope. It uses a single chr(13).

--
Bart.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MacPerl, OS 9, move file to Trash Xiong Changnian Perl Misc 1 01-26-2007 01:12 AM
Advice for moving linux script to MacPerl ecurts@neo.rr.com Perl Misc 1 03-09-2005 06:53 AM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-22-2004 10:59 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
Newbie Q: MacPerl / CGI woes will@meister.com Perl Misc 3 09-08-2003 03:17 PM



Advertisments