CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Perl Script to append character at the end is not working on windows

 



Bakkiyaraj
New User

Jan 22, 2010, 3:54 AM

Post #1 of 2 (570 views)
Perl Script to append character at the end is not working on windows Can't Post

Hi,
Below is my perl script. It appends chr(3) character at the end of each line after 211th delimiter. It works as expected in Unix but on windows it is not working, Can you please help me.

$rowcount=0;
#first print the 6.1 header
#still need to add
open(BADFILE_HDLE,">$ARGV[0]")||die("Could not open $ARGV[0]\n");

while (<STDIN>) {
chomp;
$inline=$_;
@a=split((chr 03),$inline); #Data seperator Char
$fieldcount=0;
if (scalar(@a)==211){
while ($fieldcount<=scalar(@a)){
if ($fieldcount==0) #1st field does not start with seperator
{ print "$a[$fieldcount]";}
elsif ($fieldcount==211) #Add 119 fields to the end of the data
{print chr(3).$a[$fieldcount];
for ($i=0;$i<119;$i++) { print chr(3).""};
}
else {print chr(3).$a[$fieldcount];}

$fieldcount++;
};
print "\n";

} else # print the line to the bad file
{ print BADFILE_HDLE $inline."\n";
};
};


7stud
Enthusiast

Jan 23, 2010, 4:04 AM

Post #2 of 2 (555 views)
Re: [Bakkiyaraj] Perl Script to append character at the end is not working on windows [In reply to] Can't Post


Quote
it is not working


Posting that without further explanation is unacceptable on any computer programming forum. You need to give an example of the expected output and the actual output.

Maybe this is the problem:

Code
print "\n";

On windows, perl converts "\n" to "\r\n" on output (and when reading the "\r\n" found at the end of a line, perl converts it to "\n" before handing the line over to your program).


(This post was edited by 7stud on Jan 23, 2010, 9:04 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives