develooper Front page | perl.beginners | Postings from February 2012

Re: perl and pattern

Thread Previous | Thread Next
From:
Shlomi Fish
Date:
February 21, 2012 11:57
Subject:
Re: perl and pattern
Message ID:
20120221215744.5edaf1c7@lap.shlomifish.org
Hi,

On Tue, 21 Feb 2012 23:47:39 +0400
Vyacheslav <agapov.slava@gmail.com> wrote:

> Hello.
> 
> I'm new in perl and have many questions.
> 
> This my first programm.
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 

That's good.

> my $number = 0;
> my $_ = 0;

You shouldn't use my with "$_" and you should avoid using $_ in serious
programs as much as possible because it can get devastated too easily.

> print "Enter number:";

An English typo "Enter number" should be "Enter a number".

> chomp($number = <>);
> if ( $number = /[0-9]/) {

This is wrong. You should use "=~" (the pattern match operator) instead of
"=" (the assignment one). A non-bound /.../ will match against $_. You may also
wish to use \d instead of [0-9] (though this will also match the digits used in
Arabic, etc.)

> print "you number $number\n"

1. Always include semicolons - even at end of blocks. That way your code won't
emit many spurious errors if you add more statements later.

2. You should write "Your number is $number.\n"; (Grammar nitpick).

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html

Judaism: God knows you will do shit, does nothing to prevent it, but makes you
take the blame for it anyways.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About