regex - find the occurrences of particular string in give string? -
Hi friends are now working in Perl. I need to check the string frequency in the set of arrays with the help of a pearl I can not but do anybody?
Open the file, "& lt;", "tab_name.txt" or $ !! My @ TabName = & lt; FILE & gt; My @ all_files = & lt; * & Gt; $ {$ _ = $ Tab; before my $ tab (@ tab name); My $ pgr = "PGR Usage"; If (m / $ pgr /) {for (my $ t = 0; scalar @all_files; $ t ++) {my $ file_name = 'PGR.csv'; $ _ = $ All_files [$ T]; If (m \ $ file_name \) {print $ file_name; }} Print "\ n $ tab \ n"; }}
Here's a problem:
The second part of the loop should be a condition such as: For Code> (my $ t = 0; $ t & lt; @all_files; $ t ++) { Your code will never end in writing.
However, it is much better:
foreach (@all_files) [ In addition, you have problems with your regex is. A variable in reggae is considered as a regular expression. . matches a particular character. Thus, your code will match PGR.csv , but it will also be PGRacsv , etc. and it will also match those filenames where it is a part of the name, Like FOO_PGR.csvblah . To resolve this: - Use the quote literally (
\ Q ... \ E ) to ensure that the file name is really behaved . - Anchors that match the beginning and end of the string (
^ , $ ) In addition, backslashes are valid, but they are
m / ^ \ q $ file_name \ e $ / In addition, you should put it at the top of each script that you write:
Use warnings; Strict use;
Comments
Post a Comment