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"; } }


Evan Carroll
I hack for the ladies.
www.EvanCarroll.com

In reply to Reseting pos() by EvanCarroll

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.