#!/usr/bin/perl

use Term::ANSIColor;

# clear the screen to start off
system ('clear');

##################################################################
print color("magenta"),"Part 1. Write a sub that swaps values of 2 arryas by value ",color ("reset"),"\n",
      color("magenta"),"The arrays are @a=(1,2,3) and @b=(4,5,6)",color ("reset"),"\n";
@a=(1,2,3);
@b=(4,5,6);

print "Answer:\n";
print color("green"),"\tBefore:",color ("reset"),"\n";
print "\ta = @a\n";
print "\tb = @b\n";	
&flip_flop_by_value (@a,@b);
sub flip_flop_by_value {
	@c = @_[ 3 .. 5 ];
	our @b = @_[ 0 .. 2 ];
	our @a=@c;
	return;
}
print color("green"),"\tAfter:",color ("reset"),"\n";
print "\ta = @a\n";
print "\tb = @b\n";	
##################################################################
print color("yellow"),"Part 2. Repeate exercise 1, however, this time use ",color ("reset"),"references\n";
print "Answer:\n";
my @a=(1,2,3);
my @b=(4,5,6);
print color("green"),"\tBefore:",color ("reset"),"\n";
print "\ta = @a\n";
print "\tb = @b\n";

&flip_flop_by_reference (\@a,\@b);
sub flip_flop_by_reference {
	my $array_a = shift;
	my $array_b = shift;
	#swap contents, using a temp array
	@temp=(@$array_a);
	@$array_a=(@$array_b);
	@$array_b=(@temp);	
	 ###Perl didn't like this method.###
	 #return mem-location of a as the memlocation of b.
	 #return mem-location of b as mem location of a.
	 # return ($array_b,$array_a);
	}
print color("green"),"\tAfter:",color ("reset"),"\n";
print "\ta = @a\n";
print "\tb = @b\n";	
