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 +"; } } }
In reply to Switch statement giving out error by wisemonkey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |