this was ur logic i was using .. to get the output..
#!/usr/bin/perl
use File::Copy;
use IO::File;
open my $inputfh, '<',"latestfile" or die "Failed to open latestfile $!";
my @lines = <$inputfh>;
close $inputfh;
#Remove first and last lines
my @test =shift @lines;
my @last =pop @test;
#Print lines
foreach my $last (@last) {
my @cells = split /\|/, $last;
print "@cells";
}
this was the output
$ perl text.pl
789 ADD 10
790 ADD 20
791 CHANGE 30
791 DISCONNECT 10
792 ADD 15
TRL 000000005
it was not removing the last line
That script won't produce the output you claim, unless you change this:
foreach my $last (@last) {to this:
foreach my $last (@lines) { Never retype test code in a post. Always copy/paste your actual code.
Here's an example script showing the approach I'd take.
#!/usr/bin/perl
use strict;
use warnings;
<DATA>; # throw away the first line
while ( <DATA> ) {
last if eof; # throw away the last line
tr /|/ /;
print;
}
__DATA__
HEADER|234
421|ADD|345
422|INSERT|567
421|INSERT|588
445|MULTIPLY|596
TAILER|234
Here's the results:
E:\TEMP\test>test.pl
421 ADD 345
422 INSERT 567
421 INSERT 588
445 MULTIPLY 596
(This post was edited by FishMonger on Dec 28, 2010, 6:14 AM)