Discipulus has asked for the wisdom of the Perl Monks concerning the following question:

hello monks!
I'm not able to find an error..
here the situation:

I have an @mak that can contain values in the form of h1 h2 h3... hn
I have too many different array: @h1 @h2.. @h9
My goal is foreach hn of @mak calling a sub passing to it the corrispective value of @hn (eg: h1 call sub (@h1))
@mak=qw(h1 h3 h4); #but also@mak=qw(h1 h2); etc @h1=qw(aaa1 1256 fff); @h2=qw(aaa2 3276 ggg); @h3=qw(aaa3 4860 hhh); @h4=qw(aaa4 6669 iii); foreach $zas(@mak){&scanobj(@$zas)}
if @mak contains h1 once the result of the sub but if it contains h1 h1 I find 1+2 times the result of &scanjob(@h1), if i pass h1 h1 h1 it returns 1+2+3 times the return value.

open a fishshop?
thanks in advance lor*

Replies are listed 'Best First'.
Re: idiotic syntax to pass to a sub
by Abigail-II (Bishop) on Nov 15, 2002 at 13:11 UTC
    You are using the right syntax. Make sure you are not using use strict;, as you are using symbolic references.

    You should be aware that you are using a technique many people frown upon because it's easy to create hard to find bugs.

    Abigail

Re: idiotic syntax to pass to a sub
by AcidHawk (Vicar) on Nov 15, 2002 at 13:07 UTC

    Hmmm... I'm not sure I understand you problem fully but I think you need to make sure you only have unique elements(i.e h1) in the @mak array

    @mak = qw(h1, h2, h3, h1, h3); my %mak_table = (); foreach my $num ( @mak ) { $mak_table{$num}++; print "\n\n$mak_table{$num}\n"; # Only so you can se +e what is happening } my @unique_nums = sort keys %mak_table; print "@unique_nums\n";

    Then you can use any of the unique values in the @unique_nums array.. Hope I'm not too far off the mark... that fishshop may not be a bad idea...

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
      Just a small point, but I think the first line should be
      @mak = qw(h1 h2 h3 h1 h3);
      (no commas inside the qw).

      -- Mike

      --
      just,my${.02}

Re: idiotic syntax to pass to a sub
by Sihal (Pilgrim) on Nov 15, 2002 at 13:00 UTC
    what do you mean by 1 + 2 + 3 times ?