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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subroutine problem

Status
Not open for further replies.

skottieb

Programmer
Jun 26, 2002
118
AU
hello,
im trying to write a subroutine that takes a list of numbers as an argument, that is not a problem, i can get the list into the subroutine. What I am trying to do is get the the first and second number in the list added, then the second and third, then the third and fourth and so on...
All i have been able to come up with is what is commented out in the code below. When I run it, it accecpets input fine, the figure sub runs fine, but the percent sub is the problem, it bombs out with a warning &quot;use of unitilasied value in addition (+) at C:\lovetest.pl line 53, <STDIN> line2.

here is the code:


#!perl -w

use strict;

sub input{
print &quot;Enter name of first person: &quot;;
my $name1 = <STDIN>;
chomp $name1;

print &quot;Enter name of second person: &quot;;
my $name2 = <STDIN>;
chomp $name2;

my $names = ($name1 . $name2);
return $names;
}

sub figure{
my @perc = @_;
my $letter;
my $l = 0;
my $o = 0;
my $v = 0;
my $e = 0;
my $s = 0;

foreach $_ (@perc){
$l++ while /l/ig;
$o++ while /o/ig;
$v++ while /v/ig;
$e++ while /e/ig;
$s++ while /s/ig;
}

my $letters = ($l . $o . $v . $e . $s);
return $letters;
}

#sub percent{
# my @percent;
# my $i = 0;
# my $j = 1;
# my $perc = 0;
# my $per = 0;
# my $cent = 0;
# my $pc = 0;
# my $count;
# my @perc = @_;
#
# $count = @_;
#
# while ($i < $count){
# $perc = ($perc[$i++] + $perc[$i]);
# print &quot;\n$perc&quot;;
# if ($perc > 9){
# ($per, $cent) = split //, $perc;
# push @percent, $per;
# push @percent, $cent;
# }else{
# push @percent, $perc;
# }
#
# }
#
# ($pc) = split //, @percent;
# print &quot;\n$pc&quot;;
# return $pc;
#}

my $names = input();
print $names;

my $percent = figure($names);

while ($percent > 100){
$percent = percent($percent);
} skottieb:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top