in reply to Split Tab separated text file into valid and invalid records
It took a while but eventually it sank in: Ma and the AM who wrote Split Tab separated text file into valid and invalid records (presumed to be the same person) asked two quite distinct questions. My past node replied to the AM, whilst ignoring the specs in the top node.
So (JBIC & because I have time-on-my-hands awaiting a particular event), herewith, a solution that satisfies both (I think) in one (didactic) script:
#!/usr/bin/perl use strict; use warnings; # 1055276 (see also my splitTOscalars.pl) # OP valid: $dt (AKA 'name')is alpha , datefield using slashes, balanc +edue field is numeric # second post as AM: split problems my ($dt, $account, $baldue); while (<DATA>) { chomp; ($dt, $account, $baldue) = split/\t/; # was: split("\t"); if ($dt =~ /[A-Z]+/i && $account =~ /^[\d\/]+$/ && $baldue =~ /^[\ +d.,]+$/) { print "\n VALID per OP: \$dt: $dt | \$account: $account | \$ba +ldue: $baldue \n\n"; }elsif ($dt =~ /[a-z]+/) { print "Invalid: $dt -|- $account -|- $baldue \n"; }else { print "\nValid per #1055280 \$dt, \$account, \$baldue: $dt, +$account, $baldue\n"; } } =head OUTPUT Valid per #1055280 $dt, $account, $baldue: 4-11-13, 273.13, 273.13 Valid per #1055280 $dt, $account, $baldue: 20130512, 11.17, 36.14 Valid per #1055280 $dt, $account, $baldue: 09222013, 2479.00, 6481.1 +6 VALID per OP: $dt: xyz | $account: 09/30/2013 | $baldue: 500 Invalid: abc -|- 09/30/2013 -|- YYN Invalid: del -|- hfhfh -|- 200 =cut __DATA__ 4-11-13 273.13 273.13 20130512 11.17 36.14 09222013 2479.00 6481.16 xyz 09/30/2013 500 abc 09/30/2013 YYN del hfhfh 200
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Split Tab separated text file into valid and invalid records
by Ma (Novice) on Sep 24, 2013 at 13:09 UTC | |
by ww (Archbishop) on Sep 24, 2013 at 15:06 UTC |