perl_mystery has asked for the wisdom of the Perl Monks concerning the following question:
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 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Constructing a hash with filepath,filename and filerev
by suhailck (Friar) on Dec 11, 2010 at 05:51 UTC | |
by perl_mystery (Beadle) on Dec 11, 2010 at 05:59 UTC | |
by Jim (Curate) on Dec 11, 2010 at 06:39 UTC | |
by perl_mystery (Beadle) on Dec 11, 2010 at 07:31 UTC | |
by graff (Chancellor) on Dec 11, 2010 at 19:08 UTC | |
|
Re: Constructing a hash with filepath,filename and filerev
by Anonymous Monk on Dec 11, 2010 at 05:48 UTC | |
|
Re: Constructing a hash with filepath,filename and filerev
by Marshall (Canon) on Dec 12, 2010 at 11:02 UTC |