in reply to Need to count the number of entries in a array

There is something I do not understand.

You seem to have one file per supplier and this file contains (each on its own line) title, image, a counter, the supplier's name, account number, followed by an indeterminate numbers of inventory items.

All these inventory items end up in the array @inventory. So far, so good.

Then you split the last element of the @inventory array and the delimiter is [] ("empty square brackets" -- which is strange in itself, usually the brackets contain something ...). Why is this last element of the array @inventory "special" that you can ignore all its other elements and have to split this last one?

Perhaps my ignorance can be remedied if you show the contents of one of your files so we can look at the file format?

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: Need to count the number of entries in a array
by Marshall (Canon) on Jan 16, 2012 at 10:54 UTC
    CountZero has a good question.
    my @supplier = split(/\[\]/,$inventory[$#inventory]); same as my @supplier = split(/\[\]/,$inventory[@inventory-1]); same as my @supplier = split(/\[\]/,$inventory[-1]);
    This only looks at the last element of @inventory.

    I doubt that this is what the OP really wants.

    An example file would be very helpful.

    I would also add that if the OP has input into record format, using "|" as a .csv style record separator often works out very well for DB's that contain names or addresses.