Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Array name with a Variable

by mr_mischief (Monsignor)
on Apr 17, 2008 at 21:30 UTC ( #681309=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Array name with a Variable
in thread Array name with a Variable

Actually, I think I have a bug. Let me look a little closer. Yes, I have a bug. I moved the declaration of the variables into the wrong scope. This should work a little better.

use strict; use warnings; my @array1 = qw( c d e ); my @array2 = qw( e f g h ); my @array3 = qw( a b d ); my @array4 = qw( s g h j k l ); open my $out, '>', 'output' or die "Cannot open: $!\n"; foreach my $a1 ( \@array1, \@array2, \@array3, \@array4 ) { foreach my $a2 ( \@array1, \@array2, \@array3, \@array4 ) { my ( %union, %intersect ); foreach my $item1 ( @$a1 ) { foreach my $item2 ( @$a2 ) { # print "item1: $item1\nitem2: $item2\n"; $union{$item1}++; $union{$item2}++; if ( $item1 eq $item2 ) { $intersect{$item1}++; } } } my @intersect = sort keys %intersect; print $out "@intersect\n"; #prints intersecting words print $out scalar @intersect . "\n"; } } close $out or die "Error closing output; $!\n";


Comment on Re^3: Array name with a Variable
Download Code
Re^4: Array name with a Variable
by Anonymous Monk on Feb 02, 2012 at 15:39 UTC
    [estrawser@bast1 test]$ cat arr #!/usr/bin/perl for($i=0;$i<5;$i++){ push (@$i, "foo bar $i"); print "@$i "; } print "\n"; for($x=0;$x<5;$x++){ print "@$x "; } print "\n"; [estrawser@bast1 test]$ ./arr foo bar 0 foo bar 1 foo bar 2 foo bar 3 foo bar 4 foo bar 0 foo bar 1 foo bar 2 foo bar 3 foo bar 4

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://681309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2014-11-26 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (171 votes), past polls