#!/usr/bin/perl -w use strict; sub isa_fail { die "Problem parsing ISA segment : " . shift; } sub get_delimiters { local $/ = \4; my $chunk = <>; isa_fail "ISA can't start with $chunk" unless my($ed) = $chunk =~ +/^ISA([^\w\n])$/; $/ = \101; my $num_linefeeds = scalar @{[<> =~ /\n/g]}; $/ = \($num_linefeeds + 1); my $st = substr(<>, -1); isa_fail 'Linefeeds as both delimiter and blocking' if $st eq "\n" + && $num_linefeeds; return ($ed, $st) if $st =~ /\W/; isa_fail "Segment terminator can't be $st"; } my ($elem_sep, $seg_term) = &get_delimiters; $seg_term = 'line feed' if $seg_term eq "\n"; print "Element separator = $elem_sep\n"; print "Segment terminator = $seg_term\n";
In reply to Getting an ANSI X.12 file's delimiters by delirium
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |