----- Original Message ----- From: "Alan_C" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners To: <beginners@perl.org> Sent: Saturday, April 08, 2006 8:47 PM Subject: increment operator
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.
The order of the found words depends on which line you are reading from the file (DATA in your example). The way your input file (DATA) is, it finds 'array' in line 1, and doesn't find 'word' until line 8 (even though 'word' comes before 'array' in your command line arguement list). I think that is what you want to know. Chris
#!/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>