CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Regex failing when line starts with ./

 



iphone
User

Feb 3, 2011, 1:07 AM

Post #1 of 2 (1970 views)
Regex failing when line starts with ./ Can't Post

INPUT:-

.\amss\platform\cs\bin\cdep.exe-43041;M76XXDFDCENJAD3555474RPLF.flf;//deploy/qcom/qct/core/cs/pk/rel/1.4/bin/cdep.exe - VU_CORE_CS_PK.01.04.00.07.00 : 5
./modem_proc/build/ms/dmss_flags.min-000197;M8660AAAAQNLGM107501PLF.flf;//depot/asic/msm76xx/build/ms/dmss_flags.min - 7X27_BUILD_MS.00.00.02 : 5

I have the following code which fails when the line starts with "./",how do I modify the below code to suit for both the above inputs?

OUTPUT:-
KEYS:-//deploy/qcom/qct/core/cs/pk/rel/1.4/bin/cdep.exe
//depot/asic/msm76xx/build/ms/dmss_flags.min

VALUES:-amss\platform\cs\bin\cdep.exe
modem_proc/build/ms/dmss_flags.min


Code
my %hash_basebuild_rpf;  

open my $inputfh, '<', $basebuild_rpf_file or die "could not open $basebuild_rpf_file - $!";
while (my $line = <$inputfh>) {
chomp($line);
my ($key) = $line =~ /;([^;]+)\s-\s/;
print "KEY:$key\n";
my ($value) = $line =~ /\.\\(.*);/; # this line fails when the line starts with "./"
print "VALUE:$value\n";

$hash_basebuild_rpf{$key} = $value unless (exists $hash_basebuild_rpf{$key});
}



BillKSmith
Veteran

Feb 3, 2011, 12:19 PM

Post #2 of 2 (1961 views)
Re: [iphone] Regex failing when line starts with ./ [In reply to] Can't Post

The second character does not match. Change '\\' in the RE to '[\/\\]' to allow forward or backward slash.


Code
use strict; 
use warnings;
my %hash_basebuild_rpf;
my $inputfh = *DATA;
while ( my $line = <$inputfh> ) {
chomp($line);
my ($key) = $line =~ /;([^;]+)\s-\s/;
print "KEY:$key\n";
my ($value) = $line =~ /\.[\/\\](.*);/;
print "VALUE:$value\n";
$hash_basebuild_rpf{$key} = $value
unless ( exists $hash_basebuild_rpf{$key} );
}

__END__
.\amss\platform\cs\bin\cdep.exe-43041;M76XXDFDCENJAD3555474RPLF.flf;//deploy/qcom/qct/core/cs/pk/rel/1.4/bin/cdep.exe - VU_CORE_CS_PK.01.04.00.07.00 : 5
./modem_proc/build/ms/dmss_flags.min-000197;M8660AAAAQNLGM107501PLF.flf;//depot/asic/msm76xx/build/ms/dmss_flags.min - 7X27_BUILD_MS.00.00.02 : 5



Produces the expecrted output.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives