I need to create a Perl script to examine the first four letters of the file name of all the files mentioned in the path, And compare it with those four-letter text file.
The idea is whether any file starts from the list of numbers or not.
For example, the files in the path are D: / temporary
1234-2041-123.txt 1194-2041-123.txt 3234 -2041-123.txt 1574-2041- 123.txt
I need to compare the first four letters of the file name - 1234
, 1194
, 3234
, 1574
- 1234 index
,
, 1194
, 3234
1111
, 2222
and send output with a text file containing 1574
File beginning with 1111, 2222 is unavailable
I hope I am clear
I am able to extract four letters before the file name but can not proceed
@ files <
is a way of doing this;
My @ file = & lt; D: / temp / * & gt; My% hash; Map {$ hash {$ _} = 0;} qw | 1234 1194 3234 1574 1111 2222 | | Foreach $ file (@files) {$ hash {$ 1} ++ if $ file = ~ m | Mp / (. {4}). | }; Map {printf "% s - & gt;% d \ n", $ _, $ hash {$ _}; } Grep {! $ Hash {$ _}} key% hash;
And, from there, if you change the 3 last rows ( grep
to the end):
} {$ Hash {$ a} & lt; = & Gt; $ Hash {$ b}} key% hash;
You will get count of all matching file names
similar
short (and exact match requirement) Do -;)
my @attended = qw | 1234 1194 3234 1574 1111 2222 | | My% hash; Map {$ hash {$ _} = 0;} @ rated; Map {$ hash {$ 1} ++ If M. Mp / (. {4}). } & Lt; D: / temp / * & gt; Printf "The file starting with% s is missing ... hope I'm clear! \ N", join ",", map {sprintf "'% s'", $ _} grep {! $ Hash {$ _}} key% hash;
Comments
Post a Comment