in reply to reading file in directory
It would be nice if you could have formatted your text with code-tags ... then it would be easier to identify line 18.
Nevertheless there are some issues in your code:
What do you want to acchieve with this code? It makes much more sense to use eq insted of =~ ... or change the order ("is the entered filename part of the real filename?")if ("$file" =~ "$filename")
It would have helped you to display also the filename you couldn't open. Then you would have seen that it does not contain the path. Assuming you want to open the file with the real filename (and not the filename the user entered), your could change your code toopen (FH, "$file") || die "cant open file $!";
(note: the separator between directory and filename might be different in your operating system)$filename = $dir."/".$filename; open (FH, "$filename") || die "cant open file <$filename> $!";
Now you can attack the issue with your search&replace ... there is an odd number of quotation marks (") inside your substitution, which should make you very suspicious ;-) And think again why you use grep AND s///.
HTH, Rata
|
|---|