On 18/02/2012 04:51, lina wrote:

How to make a match for the following?

"V  c #767676 " /* "0.808" */,
"W  c #6F6F6F " /* "0.846" */,
"X  c #696969 " /* "0.885" */,
"Y  c #626262 " /* "0.923" */,
"Z  c #5C5C5C " /* "0.962" */,
"a  c #555555 " /* "1" */,
"b  c #4E4E4E " /* "1.04" */,
"c  c #484848 " /* "1.08" */,

I tried the

/^\"([[:alpha:])\s+c\s+\#*\s\/\*\"(\d)*\"*/x
$dict{$1} = $2;

not work,

mainly interest the

V    0.808
W   0.846
.      .
.      .
.      .

parts

Hi Lina

Your program fails because you have just /#*/ in the middle of your
regex to match #767676 etc. when you need /#[A-Z0-9]+/. But there is no
need to match every detail of a string exactly when /.+/ will do the
trick. The program below does what you need.

HTH,

Rob


use warnings;
use strict;

while (<DATA>) {
  next unless /([A-Za-z]).+"([0-9.]+)/;
  print "$1 $2\n";
}

__DATA__
"V  c #767676 " /* "0.808" */,
"W  c #6F6F6F " /* "0.846" */,
"X  c #696969 " /* "0.885" */,
"Y  c #626262 " /* "0.923" */,
"Z  c #5C5C5C " /* "0.962" */,
"a  c #555555 " /* "1" */,
"b  c #4E4E4E " /* "1.04" */,
"c  c #484848 " /* "1.08" */,

**OUTPUT**

V 0.808
W 0.846
X 0.885
Y 0.923
Z 0.962
a 1
b 1.04
c 1.08

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to