In order for you input file to work properly for this sort of thing, it must either (a) use tab characters as column delimiters (and with no tabs or new-line characters contained within any given column value) or (b) use fixed-width columns (same number of characters per column, where each column is padded with trailing spaces as needed to fill in a fixed-width character count (*)).

If your input file is tab delimited, adjust your split statement:

my @vals = split /\t/;
(When you do the default "split" with no regex, it splits the string on one or more contiguous white-space characters of all kinds.)

If the file uses fixed-width, space-padded columns, use "unpack" as described in a previous reply.

(*) UPDATE - a better explanation of "fixed-width columns" (because my original wording was not very good): every row (line of text) would have the same number of characters; the columns in a given row can be various sizes, but each column has the same size on consecutive rows, so that column boundaries are always at the same offsets from the start of the row, and strings contained in each column would be padded with spaces as needed to maintain the character offset to the next column (or end of line).


In reply to Re: how to store text file information into my sql database by graff
in thread how to store text file information into my sql database by chella2104@gmail.com

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.