local-functions

“Variable $foo will not stay shared” Warning/Error in Perl While Calling Subroutine

天大地大妈咪最大 提交于 2019-11-30 08:00:26
问题 Update3: If you like this posting please don't upvote me but upvote the genius answer by DVK below. I have the following subroutines: use warnings; #Input my @pairs = ( "fred bill", "hello bye", "hello fred", "foo bar", "fred foo"); #calling the subroutine my @ccomp = connected_component(@pairs); use Data::Dumper; print Dumper \@ccomp; sub connected_component { my @arr = @_; my %links; foreach my $arrm ( @arr ) { my ($x,$y) = split(/\s+/,$arrm);; $links{$x}{$y} = $links{$y}{$x} = 1; } my