It looks like you are not passing arguments to your subroutine, and using @array1 as a global variable too.
You will have to pass the arg and file as parameters, and get the array as the return value.So the call will go from:
# you use strict do you? my $arg1= "foo"; my $file1="bar"; my @array1; file_processing(); foreach (@array1) { process( $_); }
to
my $arg1= "foo"; my $file1="bar"; my @array1= file_processing( $arg1, $file1); foreach (@array1) { process( $_); }
The subroutine should look like this:
sub file_processing { my( $arg, $file)= @_; # added my @array; # added $script = "/export/home/ssesar/Perl/another_script.pl -e"; $open = "$script $arg $file"; # changed open(FILE, "$open |") or die "can't do it\n";# changed while (<FILE>) { # changed chomp; next if /^\#/; next if /None/; next if /Unkno/; next if /unkno/; next if /NONE/; @_ = split ( /\n/, $_); @array = @_; } close FILE; return @array; # added }
In reply to Re: Subroutine question
by mirod
in thread Subroutine question
by Limo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |