I'm trying to sort file below using code below.I'm sorting this file by character 7 to 11 (i.e in first line it is TO1BD),which it does.After sorting I want to do is number each line.for e.g. in first line I want to replace 000200 (first six digit ) 000001 and in second line I want to replace first six digit by 000002 and so on. For that I'm trying to use for loop. but its not working.I need suggestion for that...If someone can point to me what am i doing wrong in for loop.. Thanks
Input file:
000200T01BDS100000C100001121220001002000000000000006906SQ,
000020T01BWS100000AT01B20000220001002000000000007203267Ele
000190Z80BWS100000C300000155420001002000000000000902500OUTSO
000019B02BWS100000AT01B20000220001002000000000057563144Avaya
000001T01ADS100000C200000213920001002000000000002755000ST
#!/usr/bin/perl
open (input, "<SAPPDAY.00063");
open (out, ">SAPPDAY.00063out");
#!/usr/bin/perl
#!/usr/bin/perl
#!/usr/bin/perl
open (IN, "<temp65") or die "couldn't open file for reading";
open (OUT, ">temp95")or die "couldn't open file for writing";
@EDI=<IN>;
#$number=$#EDI;
close (IN);
#$Id=substr($EDI[0],6,5);
#print $Id;
#print $number;
@temp=map{[substr($_,6,5),$_ ]} @EDI;
@temp= sort {$a->[0] cmp $b->[0]} @temp;
@ordered=map {$_->[1]} @temp;
$count=1;
#$ele=$#ordered;
#print "$ele\n";
for $x (0..$#ordered){
#$num=substr($ordered[$x],3,3);
#print "$num is right\n";
$ordered[x]=~s/(substr($ordered[$x],3,3))/$count/;
$count++;
}
print OUT @ordered;
close (OUT);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.