I ran into something that I need help understanding. In the attached
script, subroutine file_proc1 converts all elements of [at] molec to
undef, while file_proc2 does not. adjusting file_proc1 to first slurp
the file into an array "fixes it". My best guess (via dum_sub) is
that the subroutine is crossing the $_ from the processing of [at] molec
and that of the <> operator, but i'd like to know what's happening so
I can avoid this in the future.
Thanks!
script:
#!/usr/bin/perl -w
use warnings;
use strict;
use Data::Dumper;
my %name_file = (
'foo1' => 'bar/bar1',
'foo2' => 'bar/bar2',
'foo3' => 'bar/bar3',
);
my [at] molec = keys(%name_file);
print Dumper(\ [at] molec);
dum_sub($name_file{$_}) foreach [at] molec;
file_proc2($name_file{$_}) foreach [at] molec;
print Dumper(\ [at] molec);
file_proc1($name_file{$_}) foreach [at] molec;
print Dumper(\ [at] molec);
sub file_proc1{
my $file = shift;
open my $input_fh, "<", $file or die "could not open $file \n";
while (<$input_fh>) {
#do something someday
}
close ($input_fh);
}
sub file_proc2{
my $file = shift;
open my $input_fh, "<", $file or die "could not open $file \n";
while (my $line = <$input_fh>) {
#do something someday
}
close ($input_fh);
}
sub dum_sub{
print " [at] _ $_\n";
}
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
