in reply to Help Me in following code ::

gskoli:

Just a minor suggestion on your array initialization: It looks like your data may come from a table that you manually split into three vectors. In the future, you may want to try putting the table into your code like so:

my (@new_lot, @cat_one, @A_services); my @table = qw ( 1 R 182 2 R 111 3 RC 160 4 RC 105 5 R 113 6 RC 121 );

Then you can split it out into separate tables (if you like) like this:

while (@table) { push @new_lot, shift @table; push @cat_one, shift @table; push @A_services, shift @table; }

It adds a little processing time, but makes maintenance quite a bit easier. Alternatively, you can avoid the extra processing and just go ahead and make it an AoA, like this:

my @table = ( [ qw( 1 R 182 ) ], [ qw( 2 R 111 ) ], [ qw( 3 RC 160 ) ], [ qw( 4 RC 105 ) ], [ qw( 5 R 113 ) ], [ qw( 6 RC 121 ) ], );

But you'll have to change your coding a little, though, as $cat_one[2] would become $$table[2][1].

...roboticus

UPDATE: Per chromatic's fine suggestion, I changed the lines like $new_lot[@new_lot] = shift @table; to push @new_lot, it makes the code look much nicer.

Replies are listed 'Best First'.
Re^2: Help Me in following code ::
by chromatic (Archbishop) on Apr 13, 2010 at 07:53 UTC
    while (@table) { $new_lot[@new_lot] = shift @table; $cat_one[@cat_one] = shift @table; $A_services[@A_services] = shift @table; }

    May I suggest push instead?

    while (@table) { push @new_lot, shift @table; push @cat_one, shift @table; push @A_services, shift @table; }