将perl脚本转换为c++;(cppgen)文件

将perl脚本转换为c++;(cppgen)文件,perl,Perl,我有一个文件mk colors.perl,它生成rgb颜色的无序映射。 在我的makefile中,我尝试执行以下操作: all : ${EXECBIN} - checksource ${ALLSOURCES} ${EXECBIN} : ${OBJECTS} ${COMPILECPP} -o $@ ${OBJECTS} ${LINKLIBS} %.o : %.cpp ${COMPILECPP} -c $< colors.cppgen: mk-

我有一个文件
mk colors.perl
,它生成rgb颜色的无序映射。 在我的makefile中,我尝试执行以下操作:

  all : ${EXECBIN}
    - checksource ${ALLSOURCES}

  ${EXECBIN} : ${OBJECTS}
     ${COMPILECPP} -o $@ ${OBJECTS} ${LINKLIBS}

  %.o : %.cpp
     ${COMPILECPP} -c $<

  colors.cppgen: mk-colors.perl
     mk-colors.perl >colors.cppgen
以下是perl代码:

#!/usr/bin/perl
# $Id: mk-colors.perl,v 1.3 2014-05-21 15:40:52-07 - - $
use strict;
use warnings;

my %colors;
my $file = "/usr/share/X11/rgb.txt";
open RGB_TXT, "<$file" or die "$0: $file: $!";
while (my $line = <RGB_TXT>) {
  $line =~ m/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)/
     or die "$0: invalid line: $line";
  my ($red, $green, $blue, $name) = ($1, $2, $3, $4);
  $name =~ s/\s+/-/g;
  $colors{$name} = [$red, $green, $blue];
  }
  close RGB_TXT;

  print "// Data taken from source file $file\n";
  print "const unordered_map<string,rgbcolor> color_names = {\n";
  printf "   {%-24s, rgbcolor (%3d, %3d, %3d)},\n",
              "\"$_\"", @{$colors{$_}}
   for sort {lc $a cmp lc $b} keys %colors;
    print "};\n";
#/usr/bin/perl
#$Id:mk colors.perl版本1.3 2014-05-21 15:40:52-07--$
严格使用;
使用警告;
我的%颜色;
my$file=“/usr/share/X11/rgb.txt”;

打开RGB_TXT,“您的
die
语句正在执行:

$line =~ m/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)/
   or die "$0: invalid line: $line";

这表明
/usr/share/X11/rgb.txt
中的某些数据的格式与您期望的格式不符。打开此文件,找到有问题的行,并找出如何修补您的Perl脚本以正确处理它。

脚本正在编译中。您将收到一个运行时错误。不仅如此,错误消息还显示为t数据和正则表达式显然不匹配。
$line =~ m/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)/
   or die "$0: invalid line: $line";