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

Could anyone tell me meaning of following statement

foreach $e (@arr, @arr1) { $count{$e}++ }

The program is as below

@arr=qw(19205134 18630215 18453487 18416242 18338715 18227590 17698645 +); @arr1=qw(18227590 18053561 17698645 16966777); foreach $e (@arr, @arr1) { $count{$e}++ }

Replies are listed 'Best First'.
Re: Array Hash
by jethro (Monsignor) on Sep 14, 2011 at 18:05 UTC

    You could find that out easily by printing the contents of hash %count (use Data::Dumper for that, see my additions to your script). If that isn't enough you could then change your test data and observe what is changed in the output

    use Data::Dumper; @arr=qw(19205134 18630215 18453487 18416242 18338715 18227590 17698645 +); @arr1=qw(18227590 18053561 17698645 16966777); foreach $e (@arr, @arr1) { $count{$e}++ } print Dumper(\%count);
Re: Array Hash
by SuicideJunkie (Vicar) on Sep 14, 2011 at 17:59 UTC

    That's a for loop. Looping over two arrays concatenated together. Which increments a value in a hash called count.

    What part of it is confusing?

Re: Array Hash
by Anonymous Monk on Sep 15, 2011 at 07:19 UTC

    Thanks all<\p>

    Please let me know how does following work?<\p> <code> foreach $e (@arr, @arr1) { $count{$e}++ }<\code>