I need some expert help in performing the following in Perl.
I have a code below but it doesn;t seem to work. Can any expert give me some advice?
Below are the requirements
1) Open numerous files assigned to an array @FILES. Note that the files are always named with the term "sorts". Examples of these file names are "false1_sorts" , "false_sorts" , "true1_sorts" , "true_sorts" etc
2) Search for contents "32N6524" in the opened file. If contents exists, add the file to another array which is @arr_x. Here, the files that this content exist is true1_sorts" , "true_sorts"
To glob the wildcard, use <*sorts> instead of *sorts which does something altogether different than you want (you should have seen that it got printed as *main::sorts which is a globbed variable name, not a globbed file name.
What would be the syntax if i need to match a term consisting of several words for example the term "MY PERSONAL FIILE".
I tried to use the below code but it didn;t work.
Can you help ?
if ( /MY PERSONAL FILE/ ) {
push (@arr_x, $summary_x)
};
Contents for the file "true_sorts" is below.
Looks like if the term i want to match is not at the first line of the contents , then there won;t be any match.
I added the last as a minor optimization, but otherwise, this just has the brace moved to the right place, and the single quotes changed to double quotes, and corrected indentation.
The chomp doesn't appear to be necessary, but maybe you want to expand the script to the point where you do want lines to be chomped.
The matching on stuff with spaces in it is not a problem.
The double quotes is a little gotcha, but proper indentation can make an OK programmer a GREAT programmer - ALWAYS use indentation and you will have far fewer problems with code.
I have worked with other programmers who are lazy with indenting, and it makes their code 10 times harder to read.