Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I find the strings from one file in another file in Perl?
    primarykey
    data
    text
    <p>The script below takes function names in a text file and scans on a folder that contains multiple c,h files. It opens those files one-by-one and reads each line. If the match is found in any part of the files, it prints the line number and the line that contains the match. </p> <p>Everything is working fine except that the comparison is not working properly. I would be very grateful to whoever solves my problem. </p> <pre><code> #program starts: use FileHandle; print "ENTER THE PATH OF THE FILE THAT CONTAINS THE FUNCTIONS THAT YOU WANT TO SEARCH: ";#getting the input file our $input_path = &lt;STDIN&gt;; $input_path =~ s/\s+$//; open(FILE_R1,'&lt;',"$input_path") || die "File open failed!"; print "ENTER THE PATH OF THE FUNCTION MODEL: ";#getting the folder path that #contains multiple .c,.h files our $model_path = &lt;STDIN&gt;; $model_path =~ s/\s+$//; our $last_dir = uc(substr ( $model_path,rindex( $model_path, "\\" ) +1 )); our $output = $last_dir."_FUNC_file_names"; while(our $func_name_input = &lt;FILE_R1&gt; )#$func_name_input is the function name #that is taken as the input { $func_name_input=reverse($func_name_input); $func_name_input=substr($func_name_input,rindex($func_name_input,"\("+1); $func_name_input=reverse($func_name_input); $func_name_input=substr($func_name_input,index($func_name_input," ")+1); #above 4 lines are func_name_input is choped and only part of the function #name is taken. opendir FUNC_MODEL,$model_path; while (our $file = readdir(FUNC_MODEL)) { next if($file !~ m/\.(c|h)/i); find_func($file); } close(FUNC_MODEL); } sub find_func() { my $fh1 = FileHandle-&gt;new("$model_path//$file") or die "ERROR: $!"; while (!$fh1-&gt;eof()) { my $func_name = $fh1-&gt;getline(); #getting the line **if($func_name =~$func_name_input)**#problem here it does not take the #match { next if($func_name=~m/^\s+/); print "$.,$func_name\n"; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload