It works quite well for the FIRST time,but....Look:use strict; use warnings; use Tie::File; my $file_name = 'test.txt'; my @name; tie @name, 'Tie::File' ,$file_name; die "error!!!" unless defined (my $pid_1 = fork()); exit search_string(0,9999,"8888") unless ($pid_1); die "error!!!" unless defined (my $pid_2 = fork()); exit search_string(10000,19999,"18888") unless ($pid_2); die "error!!!" unless defined (my $pid_3 = fork()); exit search_string(20000,29999,"28888") unless ($pid_3); wait; wait; wait; untie @name; sub search_string { my ($from,$to,$string) = @_; for ($from .. $to) { print "the $_ th line of test.txt is $string\n" if $name[$_] = +~ /^$string$/x; } } __test.txt__ 1 2 3 ... 29998 29999 30000
Please advice!# first time the 8887 th line of test.txt is 8888 the 18887 th line of test.txt is 18888 the 28888 th line of test.txt is 28888 #second time the 8888 th line of test.txt is 8888 the 18888 th line of test.txt is 18888 the 28889 th line of test.txt is 28888 #third time the 8887 th line of test.txt is 8888 the 28887 th line of test.txt is 28888 Use of uninitialized value in pattern match (m//) at serarch_file.pl l +ine 42, <$ fh> line 29884. Use of uninitialized value in pattern match (m//) at serarch_file.pl l +ine 42, <$ fh> line 29884. Use of uninitialized value in pattern match (m//) at serarch_file.pl l +ine 42, <$ fh> line 29884. Use of uninitialized value in pattern match (m//) at serarch_file.pl l +ine 42, <$ fh> line 29884. Use of uninitialized value in pattern match (m//) at serarch_file.pl l +ine 42, <$ fh> line 29884.
In reply to regarding Tie::File by xiaoyafeng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |