I changed the DB schema - suggest you rethink yours. Anytime there are column names FOO1 FOO2 FOO3 that's a red flag of an awkward schema, however SQL Schema theory is beyond the scope of this reply.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1142225 use strict; use warnings; use DBI; $_ = 'QB Carson Palmer RB Chris Ivory RB Eddie Lacy WR A.J. Green WR J +ohn Brown WR Davante Adams TE Martellus Bennett FLEX Jeremy Hill DST +Panthers'; my $dbfilename = 'db.1142225'; unlink $dbfilename; my $db = DBI->connect_cached("dbi:SQLite(RaiseError=>1):$dbfilename"); $db->do('create table players (team text, position text, player text)' +); my %dups = /\b([A-Z]{2,})\b(?=.*\b(\1)\b)/g; # insert counts if needed for my $position (keys %dups) { my $n = 1; s/\b$position\K\b/$n++/ge; } # make hash my %db = /\b([A-Z]{2,}\d*) (.*?)(?= [A-Z]{2}|$)/g; #use Data::Dump 'pp'; pp \%db; # remove team (this is a guess) my $team = delete $db{'DST'} or die "no team"; for my $pos (keys %db) { $db->do('insert into players values (?, ?, ?)', {}, $team, $pos, $db +{$pos}); }

Here's the DB as dumped by sqlite db.1142225 .dump

PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE players (team text, position text, player text); INSERT INTO "players" VALUES('Panthers','QB','Carson Palmer'); INSERT INTO "players" VALUES('Panthers','TE','Martellus Bennett'); INSERT INTO "players" VALUES('Panthers','WR2','John Brown'); INSERT INTO "players" VALUES('Panthers','RB1','Chris Ivory'); INSERT INTO "players" VALUES('Panthers','FLEX','Jeremy Hill'); INSERT INTO "players" VALUES('Panthers','WR3','Davante Adams'); INSERT INTO "players" VALUES('Panthers','WR1','A.J. Green'); INSERT INTO "players" VALUES('Panthers','RB2','Eddie Lacy'); COMMIT;

DB Hint: come up with the several ways you will query the DB and that might help your DB schema (sample query: "get all RB". This is slightly awkward with this schema, how is it with the RB1 RB2 column name schema? )


In reply to Re: Recommendations for breaking up string? by Anonymous Monk
in thread Recommendations for breaking up string? by jdlev

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.