For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2006 > Ms-Dos and perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Ms-Dos and perl
Sverre Furberg

2006-05-27, 7:00 pm

Probably OT but...
The output of the script below isn't
what I expect.
Tested it on a computer
with ActivPerl 5.8.6 on MS Win98 SE.
---
#/usr/bin/perl

use warnings;
use strict;

my @lines;

while (<> ) {
push @lines, $_;
}

print reverse @lines[-5 .. -1];
---

When I run the script with:
C:\Temp>d_test.plx
one
two
three
four
five
<CTRL>-z

the output is:

four
three
two
one

without printing 'five' first.

Is this a Ms-Dos issue or
am I doing something wrong?

TIA
Sverre
Brian Wakem

2006-05-27, 7:00 pm

Sverre Furberg wrote:

> Probably OT but...
> The output of the script below isn't
> what I expect.
> Tested it on a computer
> with ActivPerl 5.8.6 on MS Win98 SE.
> ---
> #/usr/bin/perl
>
> use warnings;
> use strict;
>
> my @lines;
>
> while (<> ) {
> push @lines, $_;
> }
>
> print reverse @lines[-5 .. -1];
> ---
>
> When I run the script with:
> C:\Temp>d_test.plx
> one
> two
> three
> four
> five
> <CTRL>-z
>
> the output is:
>
> four
> three
> two
> one
>
> without printing 'five' first.
>
> Is this a Ms-Dos issue or
> am I doing something wrong?



Perhaps 'five' is followed by CR but not LF, so 'four' overwrites it?


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com