wisemonkey has asked for the wisdom of the Perl Monks concerning the following question:
I tried double quotes around add and sub but it didn't help. The error seems to be:switch ($opcode) { 'add' { print "\n The opcode reported was add with hex value 4 +"; } 'sub' { print "\n The opcode reported was sub with hex value 5 +"; } }
Complete code until now is something like:syntax error at ./assembly2hex.pl line 21, near "'add' { " syntax error at ./assembly2hex.pl line 22, near "'sub' { "
Any ideas? I've been reading about switch at http://perldoc.perl.org/Switch.html#!/usr/bin/perl use warnings; use diagnostics; use strict; use Switch; print ("Provide a file name to be used for source assembly code: "); my $assemblyFile = <STDIN>; print ("\n You provided a file : $assemblyFile "); open ASMFILE, $assemblyFile or die $!; while (my $instruction = <ASMFILE>) { print ("\n Current instruction is : $instruction "); my ($opcode, $operands) = split (/\s+/, $instruction, 2); print ("\n Instrction parts right now are $opcode \t $operands "); switch ($opcode) { 'add' { print "\n The opcode reported was add with hex value 4 +"; } 'sub' { print "\n The opcode reported was sub with hex value 5 +"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Switch statement giving out error
by cdarke (Prior) on Aug 26, 2011 at 07:40 UTC | |
|
Re: Switch statement giving out error
by Marshall (Canon) on Aug 28, 2011 at 16:42 UTC |