1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
my @data = <DATA>; for (my $i=0; $i <= $#data -1; $i++) { my @current = split(" ", $data[$i]); my @next = split(" ", $data[$i+1]); if ($current[2] eq $next[2]) { $data[$i] = undef; } } print @data; __DATA__ G1 X50 F30000 G1 X100 F30000 G1 X100 F3000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
use strict; use warnings; open INPUTFILE, "<", "filter.gcode" or die $!; open OUTPUTFILE, ">", "composition.gcode" or die $!; my @data = <INPUTFILE>; for (my $i=0; $i <= $#data -1; $i++) { my @current = split(" ", $data[$i]); my @next = split(" ", $data[$i+1]); if ($current[2] eq $next[2]) { $data[$i] = undef; } print OUTPUTFILE $data; } close INPUTFILE; close OUTPUTFILE; print "done";
$array[$nr + 1]
if ($nr == $#array) { next; }