Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Add new line character to and ebcdic file

by gkol0279 (Initiate)
on Apr 15, 2013 at 07:49 UTC ( [id://1028695]=perlquestion: print w/replies, xml ) Need Help??

gkol0279 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i am a bit new to perl. Need an answer: I wrote a script to convert an ascii file into an ebcdic file using the Convert::EBCDIC qw(ebcdic2ascii ascii2ebcdic). I get an input file, which i read line wise and then convert each record from ascii to ebcdic format. After conversion, i have to write this to an output file. Then read the next record and do the same and print it in the next line. After conversion this file will be sent to IBM mainframe system for further processing. Now what is happening is i append "\n" to print the next record in a new line and the \n will be in ascii and not EBCDIC. How can i convert the \n to be ebcdic in file and yet work as ascii while printing? Any suggestions?
  • Comment on Add new line character to and ebcdic file

Replies are listed 'Best First'.
Re: Add new line character to and ebcdic file
by jethro (Monsignor) on Apr 15, 2013 at 08:33 UTC

    Are you removing the \n from the ascii lines with chomp? If yes, don't do that and presumably the EBCDIC lines should have the EBCDIC equivalent of \n at the end.

    If this isn't the answer, could you tell us why there should be an \n at the end of a line even though the source file doesn't have one?

      No i am not removing \n from the ascii lines. I convert the \n to EBCDIC. But when i print all the records into a file, i find all the records in one line rather than each record a line.

        On your ASCII based machine, this is to be expected unless your editor supports EBCDIC. How does the file look on the mainframe? Do you also see everything in one line?

        Where did the newline go?
        $ perl -MData::Dump -MConvert::EBCDIC -e " dd Convert::EBCDIC::ascii2e +bcdic(qq{hi\n}); " "\x88\x89%" $ perl -MData::Dump -MConvert::EBCDIC -e " dd Convert::EBCDIC::ascii2e +bcdic(qq{\r\n}); " "\r%" $ perl -MData::Dump -MConvert::EBCDIC -e " dd Convert::EBCDIC::ascii2e +bcdic(qq{\n}); " "%"

        % must be ebcdic for \n

Re: Add new line character to and ebcdic file
by Anonymous Monk on Apr 15, 2013 at 08:27 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1028695]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found