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


In reply to Re^3: sending data thru a sub routine by kcott
in thread sending data thru a sub routine by james28909

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.