in reply to Category List

I was going to hack up a couple of examples doing it the traditional way, however, I decided to take a quick peek in CPAN. Looks like you might be interested in Array::PrintCols (alt. link). There's a pretty clear example in the module's documentation.

Just goes to show that there have been a lot of people using Perl over the years and that they've added just about everything you need to CPAN. Repeat after me: CPAN is your friend. :-)

Update (for the reply): Forgive me, but I don't find that a very convincing excuse (especially when we have some fine tutorials that show how to install modules properly--and clearly.) Taken to the extreme, it's like saying..."Well, because some people are still using Perl versions older than 5.005_03, I won't distribute any code using CGI.pm." Which would be completely absurd, of course. While I've ranted on the topic from a different angle, I think someone else said it more eloquently. The bottom line is the same. Someone else has already done the hard work. Why reinvent the wheel?

--f

Replies are listed 'Best First'.
Re: Re: Category List
by Anonymous Monk on Dec 02, 2001 at 06:47 UTC
    CPan is your friend......normally :)

    I want to avoid using too many modules as I need this script to be used on several servers, and its a little more convenient for the user if they dont need to install a module :(

    I really dont know how to approach this inside the script..
      If they are going to the trouble of installing your script on multiple machines, then you can just add the module in with your tarball and build your requires such that your script uses a local copy of the module rather than using the machine-wide modules. Other solutions would include cutting and pasting the necessary subs from the module to your script.

      As to the original question, you haven't said whether this is just splitting the data into two columns ( 1, 2; 3, 4; 5, 6; ) as you go over it or whether you want to go down the first column, then wrap to the second (1, 4; 2, 5; 3, 6 ).

      In the first case, you might consider a while loop using shift (make sure to copy the list, since shift will destroy it). In the second case, you need to split the list into two parts, then you can loop over the two half-lists by index.