in reply to Perl hashes: is there some way of adding more data to the value associated with an existing key?

It's generally a lot better (faster, cleaner, clearer) to do this type of stuff in the database. All you need is an aggregate function that concatenates strings with a space delimiter. Here are several ways to do it for PostgreSQL, SQL Server, and MySQL:

String Aggregation in PostgreSQL, SQL Server, and MySQL - Postgres OnLine Journal

With Postgres and DBD::Pg you can get an actual array instead of a delimited string.

--Daniel

  • Comment on Re: Perl hashes: is there some way of adding more data to the value associated with an existing key?

Replies are listed 'Best First'.
Re^2: Perl hashes: is there some way of adding more data to the value associated with an existing key?
by mertserger (Curate) on Jun 08, 2011 at 09:37 UTC
    Thanks to everyone for their replies.

    As Daniel pointed out, the best way was to do this in the SQL, but I wasn't sure if you could. I have yet to find a website for SQL monks! However with Daniel's pointer I found the useful Oracle function wm_concat which does what I want to data and which I never knew about before.

    You learn something every day and as always: there is more than one way to do things.
      TMTOWTDI: I like to think of awk as baby perl - a really fast baby.
      awk '{ seen[$1] = $2","seen[$1] ; } END { for (key in seen) { print key" "seen[key] ; } } ' /your/file.txt > /your/newfile.txt