#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; ########the real testing begins here################### my (@p, $file, $output_file, $data, $OUTPUT, $key, $points, $i); ###############open file for reading $file = <~/thesis/handmodel/testtext.txt>; open(DATA, "<$file"); $data = join '', ; close(DATA); ############### parse input my @points; while ($data =~ /.*?(Coordinate).*?point \[(.*?)\]/gs){ $key=$1; $points=$2; print "key is $key\n"; @p = $points =~ /(-?\d+\.\d+)/g; #print "@p"; #print "$p[1]\n"; #my @points; for ($i=0; $i < $#p; $i += 3){ push @points, [$p[$i],$p[$i+1],$p[$i+2], 1]; } #print {$OUTPUT} Dumper(\@points); print "$#points\n"; #@points = (); #clear variable } ################open file for output $output_file = <~/thesis/handmodel/testpoints.cpp>; open($OUTPUT, ">$output_file") or die "Can't open $output_file for writing: $!"; print {$OUTPUT} "\/\/Author: Phoenix\n"; print {$OUTPUT} "\/\/Description : Homogeneous coordinate values for hand model\n"; print {$OUTPUT} "\/\/\t $output_file 31 March 2006 \n\n"; print {$OUTPUT} "#ifndef POINTS_HPP\n"; print {$OUTPUT} "#define POINTS_HPP\n\n"; print {$OUTPUT} "const double points\[$#points\]\[4\] = \{\n"; for my $j ( 0 .. $#points){ my $k=0; print {$OUTPUT}"\t\{$points[$j][$k],$points[$j][$k+1], $points[$j][$k+2], 1\}" ; if ($j != $#points){ print {$OUTPUT} ",\n"; } else { print{$OUTPUT} "\n\};\n\n#endif"; } } close($OUTPUT);