> Hi, all :
>
>
> The followings are the two perl scripts:
>
> t...@camlit ~: cat test1.pl
>
> 1. #!/usr/bin/perl
> 2.
> 3. while (<DATA>){
> 4. print $line if /6/;
> 5. $line = $_;
> 6. }
> 7.
> 8. __DATA__
> 9. 1
> 10. 2
> 11. 3
> 12. 4
> 13. 5
> 14. 6
> 15. 7
> 16. 8
In this one, the first time through the loop, line 5 takes the value
of $_ which is 1.
Then the second tiime through the loop, you want to print $line (1) if
$_ matches 6 It doesnt, it goes to the next line and $line gets the
value of 2.
Eventually, $_ is 6, a match, so it prints $line whick is 5 from the
previous loop.
>
> *
> *
> t...@camlit ~: cat test2.pl
>
> 1. #!/usr/bin/perl
> 2.
> 3. while (<DATA>){
> 4. print $_ if /6/;
> 5. }
> 6.
> 7. __DATA__
> 8. 1
> 9. 2
> 10. 3
> 11. 4
> 12. 5
> 13. 6
> 14. 7
> 15. 8
>
> So my problem is what the different about the two scripts ..
>
> Because I am the perl beginner . If the question is very simple,
> please
> forgive me .
here you are simply printing $_ if $_ matches 6
You could just say, print if /6/
--
Owen
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/