hey guys my while loop is not working correctly..doesnt matter which character i enter it will still run the loop..and what it should do is test to see if character entered is 'y'(well thats what i want it to do )
thanks!!

#! /usr/bin/perl

$exp = "y";
while ($exp =="y") {
system "clear";         # clear the window

print "\nEnter the number of Widgets ordered: ";
$widgetcount = <STDIN>; #vairable to save the number of total widgerts ordered
chop $widgetcount;

print "\nEnter the number of Gidgets ordered: ";
$gidgetcount = <STDIN>; #vairable to save total number of gidget ordered
chop $gidgetcount;

print "\nEnter the number of Gadgets ordered: ";
$gadgetcount = <STDIN>; #variablet to save total number of gadget ordered
chop $gadgetcount;

print "\nEnter the number of Doodats ordered: ";
$doodatcount = <STDIN>; #vatiable to save total number of doodats ordered
chop $doodatcount;

$widgetsub = $widgetcount * 10.25; #subtotal of widgets
"assignment4.pl" 67L, 2442C written                           
[cs41s1004@cc-ccs assignments]$ vi assignment4.pl
#! /usr
/bin/perl

$exp = "y";
while ($exp =="y") {
system "clear";         # clear the window

print "\nEnter the number of Widgets ordered: ";
$widgetcount = <STDIN>; #vairable to save the number of total widgerts ordered
chop $widgetcount;

print "\nEnter the number of Gidgets ordered: ";
$gidgetcount = <STDIN>; #vairable to save total number of gidget ordered
chop $gidgetcount;

print "\nEnter the number of Gadgets ordered: ";
$gadgetcount = <STDIN>; #variablet to save total number of gadget ordered
chop $gadgetcount;

print "\nEnter the number of Doodats ordered: ";
$doodatcount = <STDIN>; #vatiable to save total number of doodats ordered
chop $doodatcount;

$widgetsub = $widgetcount * 10.25; #subtotal of widgets
$widgetsub = sprintf("%0.2f", $widgetsub); #setprecesion two decimal places
print ("\nThe total number of Widgets ordered is: $widgetcount");
print ("\nThe total value of Widgets ordered is \$$widgetsub\n");

$gidgetsub = $gidgetcount * 5.75; #subtotal of gidgets
$gidgetsub = sprintf("%0.2f", $gidgetsub); #setprecesion two decimal places
print ("\nThe total number of Gidgets ordered is: $gidgetcount");
print ("\nThe total value of Gidgets ordered is \$$gidgetsub\n");

$gadgetsub = $gadgetcount * 11.33; #subtoal of gadgets
$gadgetsub = sprintf("%0.2f",$gadgetsub); #setprecesion two decimal places
print ("\nThe total number of Gadgets ordered is: $gadgetcount");
print ("\nThe total value of Gadgets ordered is \$$gadgetsub\n");

$doodatsub = $doodatcount * 44.75; #subtotal of doodats
$doodatsub =sprintf("%0.2f",$doodatsub); #setprecesion two decimal places
print ("\nThe total number of doodats ordered is: $doodatcount");
print ("\nThe total value of doodats ordered is \$$doodatsub\n");

#total of all subtotals without taxes and shipping charges
$total=($widgetsub + $gidgetsub + $gadgetsub + $doodatsub);
$total = sprintf("%0.2f", $total);

print ("\nTotal of all products subtotal is \$$total ");

$tax = $total*.10;      #total tax on total amount
$tax =sprintf("%0.2f", $tax);
print ("\nThe total of all products tax is \$$tax");

$shipping = $total*.085;         #total shipping charges
$shipping = sprintf("%0.2f", $shipping);
print ("\nThe total of all products shipping charges is \$$shipping");

$grandtotal = $total + $tax + $shipping;        #grandtotal
$grandtotal = sprintf("%0.2f", $grandtotal);

print("\nThe grandtotal is \$$grandtotal \n");


print "Please enter 0 to quit: ";
$exp = <STDIN>;
chop $ex;
}

> #! /usr/bin/perl
First begin with

#! /usr/bin/perl -w
use strict;

Then you'll get warning about your mis-spelling

$exp = <STDIN>;
chop $ex;   # NOT exp !?

Paying attention to what you post as well would help. It looks like two attempts at copy/paste from a screen dump.

use strict;

helps to fix all typo in the src and keep your time. in development mode and debug mode it is good to use it always. live app can have it disabled for performance

When you compare alphanumeric values with the numeric comparison operator you get true when you don't expect it. Change

while ($exp =="y") {

to

while ($exp eq "y") {

Binary "==" returns true if the left argument is numerically equal to the right argument.
Binary "eq" returns true if the left argument is stringwise equal to the right argument. (from perldoc perlop)

You cannot use == to compare string or character,use 'eq' to comapre

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.