array question

Discussion in 'Perl Misc' started by Huub, Mar 18, 2007.

  1. Huub

    Huub Guest

    Hi,

    In my script I read 4 fields (2 numerical and 4 strings (i.e.
    'char'-type)) from a MySQL database to print it. This works well, but I
    want to sort the array on one of the numerical fields before printing.
    I've looked through CPAN but get lost on looking for array. Can I store
    those fields in 1 array (how?) and sort the array or is there another
    way I should do this?

    Thanks,

    Huub
     
    Huub, Mar 18, 2007
    #1
    1. Advertising

  2. Huub" <"v.niekerk at hccnet.nl wrote:
    > In my script I read 4 fields (2 numerical and 4 strings (i.e.
    > 'char'-type)) from a MySQL database to print it. This works well, but
    > I want to sort the array


    Which array?

    > on one of the numerical fields before
    > printing. I've looked through CPAN but get lost on looking for array.


    If you want to sort then the documentation for sort() should probably be
    your first information source.
    Also, there are quite a few tips in the FAQ: "How do I sort an array by
    (anything)?"

    > Can I store those fields in 1 array (how?)


    Well, technically yes, but it doesn't make much sense to store disparate
    items in the same list. You don't put your shopping list for gorceries, time
    for your next oil change, and contact list of your friends on the same sheet
    of paper either.

    > and sort the array or is there another way I should do this?


    What about an AoH (aka Array of Hash)?

    jue
     
    Jürgen Exner, Mar 18, 2007
    #2
    1. Advertising

  3. Huub

    Mirco Wahab Guest

    Huub wrote:

    > In my script I read 4 fields (2 numerical and 4 strings (i.e.
    > 'char'-type)) from a MySQL database to print it. This works well, but I
    > want to sort the array on one of the numerical fields before printing.
    > I've looked through CPAN but get lost on looking for array. Can I store
    > those fields in 1 array (how?) and sort the array or is there another
    > way I should do this?


    What exactly do you do? (Working-)code snippets?

    Why isn't it in your case possible to retrieve
    sorted records from the sql? Do you have accsess
    to the sql command?

    SELECT h.firstnumber, h.secondnumber, h.firststring, h.secondstring
    FROM huubtable as h
    ORDER BY h.secondnumber



    BTW:
    perldoc -q "How do I sort an array by (anything)?"

    Regards

    Mirco
     
    Mirco Wahab, Mar 18, 2007
    #3
  4. Huub

    Huub Guest

    Jürgen Exner wrote:
    > Huub" <"v.niekerk at hccnet.nl wrote:
    >> In my script I read 4 fields (2 numerical and 4 strings (i.e.
    >> 'char'-type)) from a MySQL database to print it. This works well, but
    >> I want to sort the array

    >
    > Which array?
    >
    >> on one of the numerical fields before
    >> printing. I've looked through CPAN but get lost on looking for array.

    >
    > If you want to sort then the documentation for sort() should probably be
    > your first information source.
    > Also, there are quite a few tips in the FAQ: "How do I sort an array by
    > (anything)?"
    >
    >> Can I store those fields in 1 array (how?)

    >
    > Well, technically yes, but it doesn't make much sense to store disparate
    > items in the same list. You don't put your shopping list for gorceries, time
    > for your next oil change, and contact list of your friends on the same sheet
    > of paper either.
    >
    >> and sort the array or is there another way I should do this?

    >
    > What about an AoH (aka Array of Hash)?
    >
    > jue
    >
    >


    Thank you.
     
    Huub, Mar 18, 2007
    #4
  5. Huub

    Huub Guest

    Mirco Wahab wrote:
    > Huub wrote:
    >
    >> In my script I read 4 fields (2 numerical and 4 strings (i.e.
    >> 'char'-type)) from a MySQL database to print it. This works well, but
    >> I want to sort the array on one of the numerical fields before
    >> printing. I've looked through CPAN but get lost on looking for array.
    >> Can I store those fields in 1 array (how?) and sort the array or is
    >> there another way I should do this?

    >
    > What exactly do you do? (Working-)code snippets?
    >
    > Why isn't it in your case possible to retrieve
    > sorted records from the sql? Do you have accsess
    > to the sql command?
    >
    > SELECT h.firstnumber, h.secondnumber, h.firststring, h.secondstring
    > FROM huubtable as h
    > ORDER BY h.secondnumber
    >


    Didn't think of this way.

    >
    >
    > BTW:
    > perldoc -q "How do I sort an array by (anything)?"
    >


    Thank you.
     
    Huub, Mar 18, 2007
    #5
  6. On Sun, 18 Mar 2007 14:41:26 +0100, Huub wrote:

    > Mirco Wahab wrote:
    >> Huub wrote:
    >>
    >>> In my script I read 4 fields (2 numerical and 4 strings (i.e.
    >>> 'char'-type)) from a MySQL database to print it. This works well, but
    >>> I want to sort the array on one of the numerical fields before
    >>> printing. I've looked through CPAN but get lost on looking for array.
    >>> Can I store those fields in 1 array (how?) and sort the array or is
    >>> there another way I should do this?

    >>
    >> What exactly do you do? (Working-)code snippets?
    >>
    >> Why isn't it in your case possible to retrieve sorted records from the
    >> sql? Do you have accsess to the sql command?
    >>
    >> SELECT h.firstnumber, h.secondnumber, h.firststring, h.secondstring
    >> FROM huubtable as h
    >> ORDER BY h.secondnumber
    >>
    >>

    > Didn't think of this way.
    >


    If the table is large and you create an index on secondnumber, this is
    also very fast, at the expense of slower insertion times.

    M4
     
    Martijn Lievaart, Mar 18, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joseph Turian
    Replies:
    11
    Views:
    522
    Joseph Turian
    Jan 19, 2005
  2. Fabio
    Replies:
    0
    Views:
    313
    Fabio
    Nov 5, 2008
  3. Mara Guida

    const and array of array (of array ...)

    Mara Guida, Sep 2, 2009, in forum: C Programming
    Replies:
    3
    Views:
    496
    David RF
    Sep 3, 2009
  4. Tom
    Replies:
    3
    Views:
    213
    salsablr
    Dec 20, 2004
  5. Tuan  Bui
    Replies:
    14
    Views:
    478
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page