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

Probably UNIX or PC vs MacOS line termination (was Re: [MacPerl] for loops)



Ann,

Syntax Checking and running the code:
>#!perl5 -w
>
>   for ($a=4; $a<8; $a+=1){
>      print "$a\n";
>   }
>
>   for ($i=0; $i<7; $i+=1) {
>      print "$i\n\r";
>   }
gives me the expected results:
># Untitled syntax OK
>4
>5
>6
>7
>0
>
1
>
2
>
3
>
4
>
5
>
6
>


One must conclude there is a problem with INDEX, @txt, or TXT.

Educated off-the-wall guess:  zero'th element of @txt is receiving the
concatenation of your whole @txt set of characters,
probabbly caused by an the input file line separator ( $/ ) being set
incorrectly (trying to process UNIX or PC files
with MacOS input file separator) or bad split argument.

If, using MacPerl, one is reading in a MacOS file (default):
  $/ = "\015";          or   $/ = "\n";
Unix input file line termination:
  $/ = "\012";          or   $/ = "\n";
PC file line termination:
  $/ = "\012\015";      or   $/ = "\r\n";
Note that in MacPerl, "\r" eq "\012"  and  "\n" eq "\015".
Very confusing, but extensively justified in prior MacPerl mailing posts.


>   for ($a=4; $a<8; $a+=1){
>      print INDEX "$txt[$a]\n";
>   # Use of uninitialized value.
>   for ($i=0; $i<7; $i+=1) {
>      print TXT "$txt[$i]\n\r";
>does it print all the lines of the list to my file, instead of just the
>first seven?

--
Regards, Larry F. Allen-Tonar        (larryat@cts.com) +1 760/746-6464 (voice)
         Principal Designer                              +1 760/746-0766 (FAX,
         P.O. Box 463072                                         upon request)
         Escondido, CA  92046-3072



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch