Hi,

[EMAIL PROTECTED]:~$ this_pl_script word array print

$size prints at 3 and it finds each of the 3 words entered on the command 
line.

But the order of the printed out found words isn't what I expected -- I had 
expected the ouput order of 1st word, 2nd word, 3rd word as entered on the 
command line.

I don't need any certain order.  But I don't understand why it prints out the 
found words in the order that it does and/or I've got something wrong in the 
code.

I'm seeking explanation, ponters to relevant doc, etc.  I'm guessing it's 
something that I've done with the increment operator.

#!/usr/bin/perl -w
use strict;

my $size = @ARGV;
print $size, "\n";

my @search4 = @ARGV;    # keywords
# to @search4 so can now set @ARGV to a file to read
# (since this is example which instead uses <DATA>)
my @list;
my $linename;
while (<DATA>) {
    @list     = split;
    $linename = shift @list;
    foreach (@list) {
        for ( my $i = 0 ; $i < $size ; $i++ ) {
            if (/$search4[$i]/) {
                print "srchword '$search4[$i]' found in:\n";
                print $linename, "\n";
                print @list, "\n\n";
            }
        }
    }
}
__DATA__
line1 map array arrays
line2 snippet replace in files
line3 capture output including errors:
line4 date prefix onto file name
line5 snippet slurp local
line6 dir operations rename files in dir cp mv very good way
line7 print character multiplied
line8 word matches
line9 array of hashes

-- 
Alan C.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to