Hi Jin,

some comments on your code:

On Thu, 26 Nov 2015 08:13:54 +0800
Jin Xu <j...@celestica.com> wrote:

> Try to use below updated ones:
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> while (my $line = <>) {

You're lacking many empty lines - separating the code into paragraphs. See:

http://perl-begin.org/tutorials/bad-elements/#paragraphs

>     while ($line =~
>         s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*#<x>#) {
>         my $result;
>         eval ("$result = $&;");

There's no need for string eval here and with interpolating double-quotes, it
won't do the right thing:

http://perl-begin.org/tutorials/bad-elements/#string-eval

Just do:

         my $result = $&;

Or if you really must:

        my $result;
        eval
        {
                $result = $&;
        };
        if ($@)
        {
                ....

Furthermore , the use of $& and friends is not advised:

http://perl-begin.org/tutorials/bad-elements/#non_recommended_regex_vars


>         $line =~ s/<x>/$result/;
> 

this can be combined into a single s/// statement.



>     }
>     print ($line);
> }
> 
> 
> 
> Regards,
> Jin Xu
> 
> 

Regards,

        Shlomi Fish



-- 
-----------------------------------------------------------------
Shlomi Fish

Please reply to list if it's a mailing list post .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to