Tuesday, 20 August 2013

why my perl code can't implement the reverse function?

why my perl code can't implement the reverse function?

Here is my code named reverse.pl
#!usr/bin/perl -w
use 5.016;
use strict;
while(my $line=<>)
{
my @array=();
push (@array,$line);
@array=reverse@array;
say @array;
}
Test file named a.txt
A B C D
E F G H
I J K L
M N O P
Q R S T
My command is perl reverse.pl a.txt
Why it can't implement the reverse function? I want to show the result is:
D C B A
H G F E
and so on.

No comments:

Post a Comment