timothy adigun wrote:
Hi lina,
     Check one script that matchs what you want below:
On Sat, Feb 18, 2012 at 5:51 AM, lina<lina.lastn...@gmail.com>  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;

    This works:
#!/usr/bin/perl
use warnings;
use strict;

while (<DATA>) {
     s/.
     (\w) # pick the single letter your $1
      \s+?\w\s
      \W
      .{6} # remove the 6 alpha-letter
      \s+?.+?
      (\d(\.\d+)?) # pick the needed digit your $2
     .*?$
     /$1$2/igmx;

Why use substitution when you are not going to use the results of that substitution? Why use the /i option when there are no alphabetic characters in the pattern? Why use the /g option when the pattern will only match once? Why use the /m option when the pattern will only match once? You shouldn't use the $1 and $2 variables unless you are sure that the pattern actually matched and the contents of $1 and $2 are valid.

BTW: \w matches more than just letters (as your comment suggests) but the OP's use of [[:alpha:]] will only match letters.


     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" */,



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
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