#!/usr/bin/perl -w # "!read username" will read username's e-mail address. # "!write username user@example.com" will set username's e-mail address # to user@example.com. # # Commands must be handled case-insensitively. use strict; print ("Hello there, what would you like to do? "); my $input_command = ; chomp ($input_command); # Break $input_command into a space-delimited array and assign only the # first element (which will be the command) to $command. my $command = (split /\s/, $input_command)[0]; $command =~ tr/A-Z/a-z/; # lowercase everything # Take the second element (the name) and assign it to $name my $name = (split /\s/, $input_command)[1]; # Take the third element and assign it to $address my $address = (split /\s/, $input_command)[2]; if ($command =~ /!read\b/ || $command =~ /!write\b/) { print ("The command you entered is $command\n"); if ($name) { print ("The name you entered is $name\n"); } if ($address) { print ("The address you entered is $address\n"); } dbhandler($command, $name, $address); } else { print ("Sorry, only !read and !write are valid commands.\n"); } sub dbhandler { my ($subcommand, $subname, $subaddress) = @_; # lowercase everything. $subcommand is already received lowercase $subname =~ tr/A-Z/a-z/; $subaddress =~ tr/A-Z/a-z/; if ($subcommand =~ /!read\b/ { open ADDYFILE, "addyfile" || die "Couldn't open file: $!"; # rest of the subroutine should go here