Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Id probably do something like
create table friends ( friend_id numeric(8) identity, first_name varchar(32) not null, last_name varchar(32) not null, hair_color varchar(6) not null, constraint PK_FRIENDS primary key (friend_id) ) go create unique index ui_no_dupes on friends ( first_name ASC, last_name ASC, hair_color ASC ) go create index i_first_name on friends (first_name ASC) go create index i_last_name on friends (last_name ASC) go create index i_hair_color on friends (hair_color ASC) go
And then I'd use DBI something like this
my $connstr="dbi::SomeDB"; my $dbh=DBI->connect($connstr,$user,$password) or die "Can't open connection to $connstr"; my $array = $dbh->selectall_arrayref(<<SQL) || die $dbh->errstr; select first_name, last_name, hair_color from friends where first_name is like "j%" and hair_color="brown" SQL print join"\n",map { join ",",@$_ } @$array;
Of course thats just me. YMMV. Oh, yeah, if it were a serious table then id put the hair color as a foreign key into a seperate table of allowed colors, for integrity purposes.

BTW, I dont really understand what the d++ is for. I would have thought you would want to iterate over your list and check each one to see if it matched your requirements. If it does then push them into a different array. Actually isnt that what grep does?

Of course you might optimise it by creating a hash of hair colors, each containing an array of elements that so match. That way you wouldnt have to search the whole list. Of course hashes arent really meant as indexes so you might want to stick with database technology, after all its to answer these types of questions that SQL and DB's were invented.

Yves / DeMerphq
When to use Prototypes?

In reply to Re: Storing Info by demerphq
in thread Storing Info by sickboy

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (7)
    As of 2019-09-20 18:38 GMT
    Find Nodes?
      Voting Booth?
      The room is dark, and your next move is ...

      Results (268 votes). Check out past polls.