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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Strange file - only CR as 'end of line'



Jul 8, 2011, 7:57 AM

Post #1 of 2 (2465 views)
Strange file - only CR as 'end of line' Can't Post

Hi all

I get a strange text file with only CR as 'end of line', from a source that is unknown to me. I assume it is created by MicroFocus COBOL on Unix server. I am prety sure it does not come from a z/OS mainframe. The records are fixed length and it might be some standard in the originating environment. I do get other fixed length files from that environment but they all have the standard CR/LF or LF.

My question is how could I tell Perl to either view 'CR only' as 'end of line' or break the file to fixed length chunks?

Thank you all



Jul 8, 2011, 1:05 PM

Post #2 of 2 (2459 views)
Re: [zatlas1] Strange file - only CR as 'end of line' [In reply to] Can't Post

Found the solution, to use the $/ (use it locally if you do not want major bugs :))


my $irs = $/;
{#<<<= anonimous
local $/ = $irs; #default
if (some condition...) {$/ = \229;}

#to allow the program to read normal as well as stupid fixed length 228 + CR characters
open (INDEXIN, "$SourceFile") or die("Couldn't open input file: $!");
while (<INDEXIN>)
chop; #if you want to get rid of the CR

... do something ...
}#<<<= end anonimous



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

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