#!/usr/bin/perl # 2024-0111: From the node: "Eliminate consecutive duplicates of list # elements. If a list contains repeated elements they should be # replaced with a single copy of the element. The order of the # elements should not be changed." use strict; use warnings; { my @orig = qw/a a a a b c c a a d e e e e/; my @correct = qw/a b c a d e/; my @soln; for ( push ( @soln, shift @orig ); @orig; ) { my $val = shift @orig; if ( $soln[-1] ne $val ) { push ( @soln, $val ); } } print "Correct solution is @correct;\n"; print "My solution is @soln.\n"; } #### push ( @soln, $val ) if ( $soln[-1] ne $val );