Lou
Lou

Reputation: 57

converting perl script to c++(cppgen) file

I have this file mk-colors.perl that makes an unorderedmap of rgb colors. In my makefile I try to do this:

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

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

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

  colors.cppgen: mk-colors.perl
     mk-colors.perl >colors.cppgen

However it seems like the perl script is not compiling correctly, this code worked fine on my work's server, but when I copied to my localmachine the perl wont compile into a cppgen file. I am runing XUbuntu 12.04, do I need to install anything new? Thanks

EDIT: I keep getting this error:

./mk-colors.perl: invalid line: ! $Xorg: rgb.txt,v 1.3 2000/08/17 19:54:00 cpqbld Exp $`

here is the perl code:

#!/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";

Upvotes: 0

Views: 250

Answers (1)

cdhowie
cdhowie

Reputation: 169038

Your die statement is executing:

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

This indicates that there is some data in /usr/share/X11/rgb.txt that isn't in the format you were expecting. Open up this file, find the offending line, and figure out how to patch your Perl script to handle it properly.

Upvotes: 1

Related Questions