On Saturday 08 April 2006 20:19, Chris Charley wrote: > ----- Original Message ----- > From: "Alan_C" <[EMAIL PROTECTED]> [ . . ] > > 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 > until line 8 (even though 'word' comes before 'array' in your command line > arguement list.
Yes, that's it. I understand it now. This is the first time that I've ever used the increment in this fashion in a for loop with the three statements or whatever they're called to the increment operator. I now see that it checks for each of the three words in a line from DATA and then it moves on to the next line of DATA I didn't fully understand (until now) the workings of those three parameters of increment in the for loop. > > #!/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 > > > > -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>