Hi Gary,

I don't know what you are trying to do with that code... :( Still, it's
valid this way:

#!/usr/bin/perl
use strict;
use warnings;

print "Content-type: text/html\n\n"; #Only if you want this format

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

    }
    print ($line);
}

If you input, for instance, 23*2 you'll get 46.

Does this help?

Kind regards,
<https://www.avast.com/?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Este
e-mail foi enviado a partir de um computador sem vírus protegido pela
Avast.
www.avast.com
<https://www.avast.com/?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Wed, Nov 25, 2015 at 3:18 PM, Olivier Le Monnier <
olivier.lemonn...@unicaen.fr> wrote:

> > gb@MINT ~/Perl5/perl programs $ cat prog164.pl
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> > while ($line = <>) {
> >     while ($line =~
> >         s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*#<x>#) {
> >         eval ("\$result = $&;");
> >         $line =~ s/<x>/$result/;
> >
> >     }
> >     print ($line);
> > }
> >
> >
> >
> > gb@MINT ~/Perl5/perl programs $ ./prog164.pl
> > Global symbol "$line" requires explicit package name at ./prog164.pl
> line 4.
> > Global symbol "$line" requires explicit package name at ./prog164.pl
> line 5.
> > Global symbol "$line" requires explicit package name at ./prog164.pl
> line 8.
> > Global symbol "$result" requires explicit package name at ./prog164.pl
> line
> > 8.
> > Global symbol "$line" requires explicit package name at ./prog164.pl
> line
> > 11.
> > Execution of ./prog164.pl aborted due to compilation errors.
> > gb@MINT ~/Perl5/perl programs $
> >
> >
> > What is this error? And what am I doing wrong.
>
>   Using strict mode, you should declare the variables scope with my for
> example…
>
> --
> Olivier Le Monnier — ☎ 023156.6209
> Administrateur systèmes libre(s)
> Direction du Système d'Information
> Université de Caen Normandie
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 


*Rui Miguel Fernandes*
*Porto - Portugal*



*Website: Cosmos - Portal Interactivo de Astronomia / Interactive Gate of
Astronomyhttp://www.cosmos.pt <http://www.cosmos.pt>*

Reply via email to