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 "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 "Enter name of first person: ";
my $name1 = <STDIN>;
chomp $name1;
print "Enter name of second person: ";
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 "\n$perc";
# if ($perc > 9){
# ($per, $cent) = split //, $perc;
# push @percent, $per;
# push @percent, $cent;
# }else{
# push @percent, $perc;
# }
#
# }
#
# ($pc) = split //, @percent;
# print "\n$pc";
# return $pc;
#}
my $names = input();
print $names;
my $percent = figure($names);
while ($percent > 100){
$percent = percent($percent);
} skottieb
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 "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 "Enter name of first person: ";
my $name1 = <STDIN>;
chomp $name1;
print "Enter name of second person: ";
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 "\n$perc";
# if ($perc > 9){
# ($per, $cent) = split //, $perc;
# push @percent, $per;
# push @percent, $cent;
# }else{
# push @percent, $perc;
# }
#
# }
#
# ($pc) = split //, @percent;
# print "\n$pc";
# return $pc;
#}
my $names = input();
print $names;
my $percent = figure($names);
while ($percent > 100){
$percent = percent($percent);
} skottieb