Perl Adding and Checking for Positive or Negative

Write a program that adds two numbers and then prints out whether the sum of those two numbers is positive or negative.

print “Please input your first number: “;
chomp($num1 = <STDIN>);           # get the first number
if ($num1 =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/)             # check for an actual decimal number
{
print “Please input your second number: “;
chomp($num2 = <STDIN>);                          # get the second number
if ($num2 =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/)             # check for an actual decimal number
{
$sum = $num1 + $num2;                # add the 2 numbers together
if ($sum==0)  # check if sum is zero since zero is not positive or negative
{
print “The number zero is neither positive or negative”;
}
elsif ($sum <0)  # if sum is negative say so
{
print “The number $sum is negative”;
}
else  # the only choice left is positive
{
print “The number $sum is positive”;
}
}
else
{
print “Hey, that second one isn’t a number!”;
#if the second entry isn’t a number, quit
}
}
else
{
print “Hey, that’s not a number! “;                        # if the first entry wasn’t a number, quit
}

July 14, 2010 · johoff · No Comments
Tags: , ,  Â· Posted in: Code

Perl Addition

Input your age into a variable called $age. Have the computer print out how old you’ll be eight years from now, ten years from now, twenty-four years from now.

print “Please input your age as a number: “;

chomp($age = int(<STDIN>));

if ($age le 0)

{

print “Hey, that isn’t a valid age!”;              # insure the user entered somehing valid

}

else

{

print “You are currently $age years old. \n”; # if age is a decimal it will be rounded

$age +=8;            # add 8 to the age

print “In 8 years you will be $age years old. \n”;

$age +=2;            # add 2 more to get the age in 10 years

print “In 10 years you will be $age years old. \n”;

$age +=14;          # add 14 more to get the age in 24 years

print “In 24 years you will be $age years old. \n”;

}

July 13, 2010 · johoff · No Comments
Tags: ,  Â· Posted in: Code

Perl code

I’ve been doing some Perl programming, and thought  I’d share some exercises with my solutions.  Remember, there is always more than one way to do things in Perl!

Make a letter-count program that counts the number of letters in a word and prints out that value.

print “Input your word: “;             # user prompt

chomp($word = <STDIN>);            # inputs the word and gets rid of the newline

$long = length($word);                   #  sets a variable with the length of the word

print “The length of your word $word is $long”;    # prints the word and the length

July 12, 2010 · johoff · 3 Comments
Tags: ,  Â· Posted in: Code

You may wonder…

You may have wondered where in the world I went. No facebook, no blog, no nothing. It is pretty much because I am taking 4 classes this summer for a master’s in bioinformatics with Johns Hopkins University.  No, I’m not really at the university, I’m taking the courses online.  Naturally this is taking most of my time.  I’m writing perl code (something new for me).  I’ve found that perl is more organic than a language like Fortran.  New modules are being added all the time, and bioperl (perl for biology stuff) just keeps on expanding.  So some things aren’t documented the way a newbie might expect.  So for the next little while, you can expect some perl code along with the pictures of how the yard is coming.  If the storm last night is any judge, the drainage is working well!

June 30, 2010 · johoff · One Comment
Tags:  Â· Posted in: Code

Cool Contest!

.

Mountain Glass Arts is one of my fave places to buy glass for making beads and sculptures.  In fact, for every order over $100 you spend there, they plant a tree!

They are sponsoring a Glass Challenge Contest.

“This is an Artists Choice Glass Challenge. Any theme is welcome as long as it is a glass creation that YOU created for this specific glass challenge. Soft or Hard glass welcome. All skill sets welcome. There will be one prize. (a $500 gift certificate!)

The winning entry will become the property of MGA and will need to be shipped to MGA before prize will be issued. The piece will be placed in a show case that is on display now showcasing other’s work. The winning entry will also have the artists information attached to piece. The staff and owners of MGA will be picking the winner.”

The deadline is August 31st, 12pm EST ~ ALL skill sets are welcomed and encouraged to join in this challenge!  Since it says all skill sets, that means I can enter!  Now I just have to think up a good idea….

Here is one of the previous challenge winners:

By GinkoGlass

The organizer for these contests is The Glass Challenge, and you can get more info on them by following the happy link. :)

June 12, 2010 · johoff · No Comments
Tags: , , , ,  Â· Posted in: Uncategorized

The drainage pit.

This is what the drainage pit looks like.  Mostly that is.  The stuff on the rocks washed there after a big storm, but it is mostly gone now.  And I have finished the border around the area.  Many thanks to Kurt and Daphne for the wonderful zombie!  Unfortunately he floats, so we are going to have to figure out some way of tying him down.

Drainage area.

Zombie!

June 11, 2010 · johoff · No Comments
Tags: , ,  Â· Posted in: Uncategorized

The deck is almost done

It still needs to be stained, which will happen in a week or so.  Evidently you have to wait 2 weeks to stain and waterproof a new deck.  Not sure why, but the construction people say it is true.  I’ll have more pictures of the deck when it is really finished.

Dogs love the new deck!

It has a great rail to put the strawberry pots on.

June 10, 2010 · johoff · One Comment
Tags:  Â· Posted in: Uncategorized

Grass!

We have achieved grass.  Very short grass for right now, and it needs to be watered every day, if not twice a day.  It is growing in sort of strange since we had a rain storm right after we planted it, and the seed ended up mostly in the hollows… including in footprints!  It looks like bigfoot walked across our yard and grass grew where he stepped.

baby grass and peat moss

Chris watering the grass with his mighty hose.

June 9, 2010 · johoff · 2 Comments
Tags: ,  Â· Posted in: Uncategorized

Snakes on a Plane

Snakes! On a Plane!

I really enjoy the movie Snakes on a Plane.  Over and over again.  I’m just that kind of girl.  So I watched it with Andrea while I was in Atlanta.  In return she sent me this picture of snakes on a plane.  Perfect for all you math people out there.   If you click on the picture it should (cross your fingers) take you to the site it came from.  Oh, and if you want to see some really neat jewelry, you should visit Andrea’s site.

May 31, 2010 · johoff · No Comments
Tags:  Â· Posted in: Uncategorized

Bird Tape

Our little tree

We have a mini cherry tree with 5 different varieties of cherries on it.  In previous years it would get cherries, and the birds would get most  of them.  We tried bird netting, but it seemed like the birds would land on the netting and eat the cherries through it.  So this year we tried bird tape.  It is mylar, like the stuff they make balloons out of, red on one side and silver on the other.  It gets strung around the tree so it twists and shimmers in any sort of breeze.  Would you believe it works?  We got about 6 quarts of cherries off our little tree this year! Some of the cherries were packed so tight on the tree they bruised each other.  Chris made a yummy lemon tart with cherry topping.  We even froze a bag for winter.

See the bird tape!

Loads of cherries!

May 30, 2010 · johoff · No Comments
Tags: , ,  Â· Posted in: Uncategorized