Ok what I've got is a flat-file DB with static-char-width cells. Each "cell" beings at the character that the respective header col starts with. nothing special here.
Trick is some of these columns have random amounts of spaces in them so I wish to automate this to the extent that I provide an unordered column list and it returns the unpack string with the specific format.
So what I'm trying to do is abuse regex's and pos() to accomplish this. Someone please tell me why this script fails returning "ERROR: NOCOL C/T ENG". I've tried to assign pos=undef and failing a match to get pos to reset itself. Thanks for the help
#!/usr/bin/env perl use strict; use warnings; use feature ':5.10'; my $titles=' STOCK N/U YR MAKE BODY COLOR VIN + INV DTE AGE ORIG COST PKD COST PK CST + HB CURR COST + FLR PL / AP RETAIL STOCK C/T ENG MODEL SERIES + TRIM PO/RO MILES OPTIONS ' ; my @cols = ( qw( STOCK N/U YR MAKE BODY COLOR VIN COST STOCK MODEL SERIES TRIM PO/RO MILES OPTIONS ) , 'C/T ENG' , 'INV DTE' , 'AGE ORIG' , 'PKD COST' , 'PK CST + HB CURR COST' , 'FLR PL / AP RETAIL' ); foreach my $col ( @cols ) { my $recol = quotemeta( $col ); $titles =~ m/$recol/g; unless ( pos($titles) ) { say "ERROR: NOCOL $col"; } }
In reply to Reseting pos() by EvanCarroll
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |