All pastes #252734 Raw Edit

Miscellany

public text v1 · immutable
#252734 ·published 2006-11-19 22:26 UTC
rendered paste body
#!/usr/bin/perl

$clear_string = `clear`;  # Clear string


# Take in names.
@names;
$again = "y";
print "Would you like to add a name? (y,n)  ";
while ($again eq "y") {
#	print "Add another name? (y,n)  ";
	$again = <STDIN>;
	chomp($again);
	if ($again eq "y") {
		print "What is the name?\n";
		chomp($current_name = <STDIN>);
		push(@names, $current_name);
		print "Would you like to add another name? (y,n)  ";
	}
	elsif ($again ne "y" && $again ne "n") {
		print "INVALID SELECTION; Try again. (y,n)\n";
		$again = "y";
	}
	else {
		print "The names entered thus far:\n @names\n";
	}
}
print 'Number of elements in @names ' . "$#names\n";

# include address line 1

@address_line_one;
$number_of_entries = $#names;
$total = $#names;
while ($number_of_entries >= 0) {
	print "Please enter the street address for $names[$total - $number_of_entries].\n";
	chomp($current_address = <STDIN>);
	push(@address_line_one, $current_address);
	$number_of_entries = $number_of_entries - 1;
}

# print the name and address

print $clear_string; #clear the screen

$number_of_entries = $total;
while ($number_of_entries >= 0) {
	print "$names[$total - $number_of_entries]\n";
	print "$address_line_one[$total - $number_of_entries]\n";
	print "Press ENTER to continue. \n";
	<STDIN>; # pause and wait for keystroke
	$number_of_entries = $number_of_entries - 1;
}

# Add Apartment, if applicable

@address_line_two;

$number_of_entries = $total;
while ($number_of_entries >= 0) {
	print "Does $names[$total - $number_of_entries] live in an apartment? (y,n)  ";
	chomp($again = <STDIN>);
	if ($again eq "y") {
		print "What is the apartment number?\n";
		chomp($current_address = <STDIN>);
		push (@address_line_two, $current_address);
		$number_of_entries = $number_of_entries - 1;
	}
	else {
		$number_of_entries = $number_of_entries - 1;
		push (@address_line_two, undef);	# keeps the organization correct
							# with the index of the names
	}
}

# print current address information

$number_of_entries = $total;
print $clear_string;
while ($number_of_entries >= 0) {
	print "$names[$total - $number_of_entries]\n";
	print "$address_line_one[$total - $number_of_entries]\n";
	if ($address_line_two[$total - $number_of_entries] eq undef) {	# avoids printing
									# a blank line for
									# the apartment
	}
	else {
		print "$address_line_two[$total - $number_of_entries]\n";
	}
	$number_of_entries = $number_of_entries - 1;
	print "Press ENTER to continue...\n";
	<STDIN>
}

# take in the city, state, zip

$number_of_entries = $total;
while ($number_of_entries >= 0) {
	print "What is $names[$total - $number_of_entries]'s city?\n";
	chomp($current_address = <STDIN>);
	push (@city, $current_address);
	print "What is $names[$total - $number_of_entries]'s state?\n";
	chomp($current_address = <STDIN>);
	push (@state, $current_address);
	print "What is $names[$total - $number_of_entries]'s zip code?\n";
	chomp($current_address = <STDIN>);
	push (@zip, $current_address);
	$number_of_entries = $number_of_entries - 1;
	print "$clear_script"
}

# print out the final addresses

$number_of_entries = $total;
while ($number_of_entries >= 0) {
	print "$names[$total - $number_of_entries]\n";
	print "$address_line_one[$total - $number_of_entries]\n";
		if ($address_line_two[$total - $number_of_entries] eq undef) {
		}
		else {
			print "$address_line_two[$total - $number_of_entries]\n";
		}
	print "$city[$total - $number_of_entries],";
	print " $state[$total - $number_of_entries] ";
	print " $zip[$total - $number_of_entries]\n";
	$number_of_entries = $number_of_entries - 1;
	print "Press ENTER to continue...";
	<STDIN>
	print "\n\n";
}