in reply to Re^2: sending data thru a sub routine
in thread sending data thru a sub routine

system_prompt>my_script.pl $file1 system_prompt>my_script.pl $file2

If you're really doing this, with no intervening actions, and always having two files to process, you could instead do this:

system_prompt>my_script.pl $file1 $file2

And then, in my_script.pl:

die "Usage: $0 file1 file2" unless @ARGV == 2; ... for (@ARGV) { process_file($_); } ... sub process_file { my ($filename) = @_; open my $input_fh, '<', $filename or die "Can't open '$filename': +$!"; ... }

You have other issues in your code which you'll need to address. One that leapt out at me was this infinite loop:

my $exit = ''; until ($exit) { ... code where $exit never becomes TRUE ... }

You have two last statements but both are conditional on a pattern match. You should really have a bailout option, i.e. if you've done everything possible in the loop but are still looping, then die, warn and last or similar — and, instead of until ($exit) {...}, use while (1) {...} and get rid of the $exit variable altogether.

sub infile($file1); #will this be passed to ARGV[0]? ... sub infile(file2); #will this be sent to ARGV[0] as well after the fi +rst file?

Your (commented) questions about passing/sending to ARGV[0] [which should be $ARGV[0]] suggest you haven't really got a handle on the @ARGV array but, unfortunately, I don't know what you haven't understood. Take a look at "perlvar: Variables related to filehandles" and "perlop: I/O Operators". See what both of those sections say about @ARGV: that should either clarify the purpose and usage of @ARGV or, if not, provide you with the basis for more specific questions.

-- Ken

Replies are listed 'Best First'.
Re^4: sending data thru a sub routine
by james28909 (Deacon) on May 12, 2014 at 01:54 UTC
    the last statement /can/ be one of many, and in my code you will see that i can add a last statement before or after formatting from hex to plain text, which is great that i could understand that, but on my observance in the files, it will always end with just the two that are in my code, if i come across a different "last" statement then i can easily add it in. the infinite loop would only happen if i didnt know what was in the file ;)
    im just trying to grasp the subroutine stuff :) i admit i am still pretty new to perl but it has been by far the best language to use so far.
    thanks for the ideas man, cheers :)