Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

RE: RE: Re: Subroutine question

by jreades (Friar)
on Sep 21, 2000 at 07:49 UTC ( [id://33445]=note: print w/replies, xml ) Need Help??


in reply to RE: Re: Subroutine question
in thread Subroutine question

Right, here's what we're saying:

my @array1; my @array2; my @args = ( [ \@array1, "foo", "file_1.gz"], [ \@array2, "bar", "file_2.gz"] ); foreach (@args) { &file_processing($args->[0], $args->[1], $args->[2]); } sub file_processing { my ($array_ref, $arg, $file) = @_; my $script = "/export/home/ssesar/Perl/another_script.pl"; open(FILE, $script . ' ' . $arg . ' ' . $file . ' |') or die ("c +an't do it: $!\n"); while (<FILE>) { chomp; push @{$array_ref}, $_ unless /^(?:\#|none|unknow)/i; } close FILE; }

This should do what you want as best as I can tell -- open a file and push into an array (either array 1 or array 2 depending on which iteration) any line that doesn't start with UNKNOW/unknow/#/NONE/none.

Your lines

@_ = split ( /\n/, $_); @array1 = @_;

look very strange -- as someone else pointed out, if you're reading in the file line by line (which is what <FILE> implies) then the final split on \n is useless.

In addition, you're only assigning the last value of @_ to @array1 (meaning the other values are lost) unless you've undefined $/, in which case you should just use my $file = <FILE> rather than the while loop.

Hope this helps.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found