Hi prospect,
Point #1: Always ALWAYS use strict; and declare your vars with my()!
Now, from your post it is not clear whether you want to check the result of an arithmetic operation, or the length of a string.
The x operator in Perl is not the multiplication operator, but the string (or list) repetition operator. See perlop.
Thus your code creates a string from repeating $string $num times.
To check the length of a string (the only thing that makes sense if you are using x), use length.
use strict; use warnings; use feature 'say'; print 'Enter a string: '; chomp( my $string = <STDIN> ); print 'Enter a number: '; chomp( my $num = <STDIN> ); my $result = $string x $num; say "The result is :\n $result"; my $length = length $result; if ( $length >= 100 ){ say "Length $length is too big, bye"; } else { say "Length $length OK"; }
In reply to Re: result is not listening to if
by 1nickt
in thread result is not listening to if
by prospect
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |