On 02/21/2012 01:47 PM, Vyacheslav wrote:
Hello.
I'm new in perl and have many questions.
This my first programm.
#!/usr/bin/perl
use strict;
use warnings;
EXCELLENT START!
my $number = 0;
my $_ = 0;
print "Enter number:";
chomp($number = <>);
if ( $number = /[0-9]/) {
You want the match operator to match against $number.
if ( $number =~ /[0-9]/ ) {
What your program is doing now is saying "Set $number to the boolean
value of "does $_ have a digit in it?"
print "you number $number\n"
}
Note that /[0-9]/ will also match strings like "N1GAK" and "23 skidoo",
which may not be what you want.
if ( my ($only_number) = $number =~ m/([0-9]+)/ ) { ...
says ... "consider the string $number ... if there is a string of at
least one digit in it, assign that to $only_number, and then execute the
block .... "
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/