MacPerl vs. Unix (OS X) Perl

Discussion in 'Perl Misc' started by Nathan Olson, Jul 12, 2004.

  1. Nathan Olson

    Nathan Olson Guest

    Any reason why the following behaves differently from MacPerl to Unix Perl
    (in OS 10.2.8)? (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
     
    Nathan Olson, Jul 12, 2004
    #1
    1. Advertising

  2. Nathan Olson <> wrote in
    news:BD177587.14163%:

    > Any reason why the following behaves differently from MacPerl to Unix
    > Perl (in OS 10.2.8)? (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
    d
    (remove '.invalid' and reverse each component for email address)
     
    A. Sinan Unur, Jul 12, 2004
    #2
    1. Advertising

  3. Nathan Olson

    Jim Keenan Guest

    Nathan Olson <> wrote in message news:<BD177587.14163%>...
    > Any reason why the following behaves differently from MacPerl to Unix Perl
    > (in OS 10.2.8)? (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] ??
     
    Jim Keenan, Jul 12, 2004
    #3
  4. In article <Xns95241609DAC50asu1cornelledu@132.236.56.8>,
    "A. Sinan Unur" <> wrote:

    > Nathan Olson <> wrote in
    > news:BD177587.14163%:
    >
    > > Any reason why the following behaves differently from MacPerl to Unix
    > > Perl (in OS 10.2.8)? (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
     
    Iain Chalmers, Jul 13, 2004
    #4
  5. Iain Chalmers <> wrote in
    news::

    > In article <Xns95241609DAC50asu1cornelledu@132.236.56.8>,
    > "A. Sinan Unur" <> wrote:
    >
    >> Nathan Olson <> wrote in
    >> news:BD177587.14163%:
    >>
    >> > Any reason why the following behaves differently from MacPerl to
    >> > Unix Perl (in OS 10.2.8)? (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
    d
    (remove '.invalid' and reverse each component for email address)
     
    A. Sinan Unur, Jul 13, 2004
    #5
  6. In article <Xns9525228F3EDAasu1cornelledu@132.236.56.8>,
    "A. Sinan Unur" <> wrote:

    > Iain Chalmers <> wrote in
    > news::
    >
    > > In article <Xns95241609DAC50asu1cornelledu@132.236.56.8>,
    > > "A. Sinan Unur" <> wrote:
    > >
    > >> Nathan Olson <> wrote in
    > >> news:BD177587.14163%:
    > >>
    > >> > Any reason why the following behaves differently from MacPerl to
    > >> > Unix Perl (in OS 10.2.8)? (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
     
    Iain Chalmers, Jul 13, 2004
    #6
  7. Nathan Olson

    Bart Lateur Guest

    Tim Hammerquist wrote:

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


    Nope. It uses a single chr(13).

    --
    Bart.
     
    Bart Lateur, Jul 13, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,824
  2. Newbie Q: MacPerl / CGI woes

    , Sep 8, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    147
    Vlad Tepes
    Sep 8, 2003
  3. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    290
    Michele Dondi
    Jan 22, 2004
  4. Replies:
    1
    Views:
    122
    A. Sinan Unur
    Mar 9, 2005
  5. Xiong Changnian

    MacPerl, OS 9, move file to Trash

    Xiong Changnian, Jan 25, 2007, in forum: Perl Misc
    Replies:
    1
    Views:
    166
    Xiong Changnian
    Jan 26, 2007
Loading...

Share This Page