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:
Strange file - only CR as 'end of line'

 



zatlas1
Novice

Jul 8, 2011, 7:57 AM

Post #1 of 2 (1357 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

ZA


zatlas1
Novice

Jul 8, 2011, 1:05 PM

Post #2 of 2 (1351 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 :))


Code
       

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



ZA

 
 


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

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