I am trying to construct a hash ,a input file which contains the following lines, the hash should contain the filename as key and the filepath and the filerev as values,I wrote the below sample code but am not sure if it works.Can someone look at the code ?
INPUT:-File containing following lines //depot/asic/tools/perl/scripts/examples/modem.c#7
//depot/asic/tools/perl/files/examples/file.txt#2
//depot/asic/tools/perl/proc/examples/apps.c#14 ......
OUTPUT:-Hash should be constructed as follows hash{file_path}=//depot/asic/tools/perl/scripts/examples/modem.c hash{file_name)=modem.c hash{file_rev)=7
my %hash = (); print "Enter File "; my $file_name = <>; chomp($file_name); open my $DATA, '<', $file_name or die "Cannot open file 2\n"; while (my $line = <$DATA>){ hash{file_path} = $line =~ /\/\/.*[#]/xms; #match "//" and them ma +tch everything until pound(#) hash{file_name) = $line =~ /[\/]+?(\w+)\#/xms; #Get the filename b +etween last frontslash "/" and pound(#) hash{file_rev) = $line =~ /[#](\d+)/xms;#Match the number after po +und (#) sign }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |