You are on the right idea. Perl is different than C in many respects. One noticeable things is that subscripts like $ARGV[0] are strangely absent. Here are some command line things that would call my_prog..

>perl my_prog somename name2 name3 name4
>perl my_prog somename name2
>perl my_prog somename
>perl my_prog *.txt
Here is the code:

#!/usr/bin/perl -w use strict; die "must have at least 2 files\n" if @ARGV <2; my ($first_file, @other_files) = @ARGV; open(IN, '<', "$first_file") || die "can't open $first_file $!"; while (<IN>) { #work on each line in the first file } foreach my $file (@other_files) { open (IN, "<", $file) or die "can't open $file $!"; while (<IN>) { #work on each line in the sub files } }
BTW:
- in C $argv[0] is program name, in Perl $0 is, "well sort of" and is more complex than it sounds amongst O/S'es, but that is the basic idea.
- in Perl @ARGV contains the number of args (could be expanded by shell)

In reply to Re: diamond operator by Marshall
in thread diamond operator by Anonymous Monk

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.