A user supplies a file which has a header and a number of rows. The header takes the form:

FA1 '|' FA2 '|' FA3 '|' FA4 [ '|' VA1 .. ]

where FAn are always-required attribute ids and VAn are zero or more optional attribute ids of no particular limit in number.

The rows thereafter are values for insert or update to the database.

The problem is that when using the split command:

my ( $f1, $f2, $f3, $f4, @v ) = split( /\|/ );
(under perl version 5.6.1 if that matters) any trailing empty fields are missed from the list, i.e. a DWIM split would convert A|B|| into ['A','B', undef, undef, undef ]or I'd even be able to cope with ['A','B','','',''] but in practice perl split is returning only ['A','B'], preventing me from knowing whether the user entered A|B, A|B||| or for that matter A|B||||||||||||||||||||||||||||||||||||

I can see that tuning up the regexp is probably the way to go here, but I don't know how.

Thanks in advance.

-M

Free your mind


In reply to split problem when emptiness is a valid element by Moron

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.