in reply to Re^5: Help with Search String
in thread Help with Search String

i have a question I have put this together and it works great in Solaris, but in Linux the search results show everything. Got any ideas?
use strict; use warnings; my $namesFile = q{names.txt}; open my $namesFH, q{<}, $namesFile or die qq{open: $namesFile: $!\n}; my @names = <$namesFH>; close $namesFH or die qq{close: $namesFile: $!\n}; chomp @names; # Remove line terminators my $namesPatt = join q{|}, @names; my $dataFile = q{data2.txt}; open my $dataFH, q{<}, $dataFile or die qq{open: $dataFile: $!\n}; # while ( <$dataFH> ) # { # print qq{Found name $_\n} if /($namesPatt)/; my $outFile = q{/home/btobin/data3.txt}; open my $outFH, q{>}, $outFile or die qq{open: $outFile: $!\n}; while ( <$dataFH> ) { print $outFH qq{Found name $_\n} if /($namesPatt)/; } close $outFH or die qq{close: $outFile: $!\n}; # } close $dataFH or die qq{close: $dataFile: $!\n};

Replies are listed 'Best First'.
Re^7: Help with Search String
by johngg (Canon) on Dec 08, 2007 at 12:09 UTC
    To answer your previous post, yes, change q{>>} to q{>} as you have already discovered :-)

    Regarding Solaris versus Linux, I work mostly on Solaris but occasionally port my scripts to Linux. I have never had problems when doing that so I don't really know what might be going wrong. Check the obvious like making sure you have the same data files and script on both systems. After that it is probably a case of scattering extra print statements through you script to check that the data you think you are working with is in reality what you expected.

    Sorry I can't be of more help.

    Cheers,

    JohnGG