#!/usr/bin/perl use strict; sub csv_split { local $_ = shift || return undef; my @array = (); my $count = my $quoted = 0; while ( s/(.)// ) { my $char = $1; if ($char eq ',' && !$quoted) { $count++; next; } if ($char eq q/"/) { unless ( $quoted && s/^\"// ) { $quoted = 1 - $quoted; next; } } $array[$count] .= $char; } return @array; } for my $line () { print "\nLine: $line"; print "$_\n" for csv_split $line; } __DATA__ Simple cells,test,test Cells with commas,"test 1a,1b","test, 2a 2b" Cells with quotes,"test ""one""","""test"" two" Quotes and commas,"test ""1a,1b""","""test 2a,""2b" #### sub handle_edi { my ($bank_name, $bu, $amt); local $/ = shift; open INFILE, shift; my $dlm = undef; while () { if ( /^ST(\W)820/ ) { $dlm = $1; } elsif ( $dlm && /^SE$dlm/ ) { undef $dlm; } elsif ( $dlm && /^BPR$dlm/ ) { my @sg=split "\\$dlm"; $bank_name = $who{$sg[7]} || 'undefined'; $amt = $sg[2]; $amt =~ s/\.//g; $bu = &getbu ($sg[9]); $buhash{$bu}{bankname}=$bank_name if !defined $buhash{$bu}{bankname}; $buhash{$bu}{count}{edi}++; $buhash{$bu}{$amt}{edi}++; } } close INFILE; } #### my %sc = qw ( \\* b / em _ u ); my %counts; my %opened; sub track { $opened{$_} = 1 - ( $opened{$_} || 0 ); return "<$sc{$_}>" if --$counts{$_} > 0 && $opened{$_}; return "" if ! $opened{$_}; $_; } sub reg_fix { my $line=shift; %counts = (); %opened = (); $line =~ s/<([^>]*<)/\<$1/g; # Replace unmatched < with < my @elems = split '(<.*?>)', $line; $line =~ s/<.*?>//g; $counts{$_} = @{[$line =~ m/$_/g]} for keys %sc; for my $elem ( grep !/^## $YYYYMMDD = 19000100+sprintf"%02d"x3,(localtime)[5,4,3]; #### find .|perl -lne'$t{19000100+sprintf"%02d"x3,(localtime((stat)[9]))[5,4,3]}+=-s if!-d}{print"$_ $t{$_}"for sort keys%t' #### #!/usr/bin/perl while(1) { if (!$ARGV || /^IEA/) { $/ = \1; 1 while ($_ = <> || last) =~ /\s/; $/ = \104; die "Interchange can't start with $_" unless ($_ .= <>) =~ /^ISA[^\w\n]/; $/ = \(1 + y/\n//); $/ = substr( ($_ .= <>) , -1); die "Invalid terminator in $ARGV" if /\w$|\n.*\n$/ || ! s!\n|$/!!g; } else { last if !defined (($_ = <>) =~ s!\n|$/!!g); } print "$_\n"; } #### $_="123 456 789 147,258,369,159,357";$p=X;sub d{/.{12}/s;print$&.$p;die$_ for@_} n:d;$m=<>until$m=~/\d/&&s/$&/$p/g;/$p{3}/?d$p:!/\d/?d"Tie":$p=~y/XO/OX/;goto n