Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create aMethod Which return some value

Status
Not open for further replies.

6681510

Programmer
Aug 29, 2007
16
0
0
FI
Code:
#!/usr/bin/perl

use CGI qw(:all);


print header;

##creating html page
print start_html('Offer Calculator'),
    h1(' Offer Calculator'),
    start_form,
       	print '<TR><td class="text">';

		print"<select name='Product' >";
		print "<option value='FCWQ'  class='text' checked='checked'>'Product1'<br>";
		print "<option value='FCCL'  class='text'>'Product2'<br>";
		print "<option value='FCWQ' class='text'>'Product3'<br></td><td class='text' valign='top'>\n";
                print"</select>";
              	print	TR(td(br,submit(-name=>'action',-value=>'calculate')));
    end_form,
my $input = param('Product');
my $pricedata = "mst_fi_03102007.txt";
##########Method which will get the price from a text file
#But there are some parameters needs to be in put first
sub GetPrice{

my ($Product,$type,$Customer,$VBA,$Region,$PriceData) = @_;
my $price = 0;
#Open data file and read it to an array
open(FILE, $PriceData) or die "Can't open C:/usr/Offer_Calculator/M_Offer_cal/pricedata_se_siebal.txt:$!\n";
while(<FILE>) {
 #Split each line by white space
 @tmp = split /\s+/, $_;
 my $sku = $Product . $type . $Customer . $VBA . $Region;

 #Check if first data is equal and if it is print second values
 if ($tmp[0] eq $sku) {
  $Product = substr($tmp[0],0,4);
  $type = substr($tmp[0],4,3);
  $Customer = substr($tmp[0],7,1);
  $Vba = substr($tmp[0],8,3);
  $Region = substr($tmp[0],11,2);
  $price = $tmp[1];
  print "The complete Product SKU = $tmp[0]\n<br>";
  print "Price = $tmp[1]\n<br>";
  print "productcode = $product\n<br>";
  print "Product Type = $type\n<br>";
  print "Customer = $Customer\n<br>";
  print "Value Band = $Vba\n<br>";
  print "Region = $Region\n<br>";
  }
}

return $price;
close FILE;
}

my $ProductPrice = GetPrice($input,"BF1","N","VBA","IN",$pricedata);
print "Price of product $ProductPrice";



print end_html;

The Code above will generate a page which will have dropdown box and the value of that box is 'FCWQ' OR 'FCCL' etc and when the button is press then there is a method(GetPrice) which will return a price of that product which value is behind the dropdown box from txtfile the txt file looks like this

Code:
FCWQBF1NVBAIN	80	EUR
FCWQBF1NVBBIN	60,92	EUR
FCCLQBF1NVBBIN	60,81	EUR
FCWEBF1NVBBIN	60,90	EUR

Now the problem is the method id not retuning any value it is printing the correct price but , Please help me in this thanks.
 
Well I have found the solution. i dont need to substr any of the parts of the Product code then the method will retun value .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top