Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: how to store text file information into my sql database

by graff (Chancellor)
on Dec 27, 2015 at 00:34 UTC ( [id://1151210]=note: print w/replies, xml ) Need Help??


in reply to how to store text file information into my sql database

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).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1151210]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (1)
As of 2024-04-24 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found