
p3aul
Novice
Jul 27, 2012, 11:53 PM
Post #1 of 5
(970 views)
|
|
Help with simple command line program
|
Can't Post
|
|
I'm writing this to be used as a simple program to be run on the gnome terminal in Ubuntu. I have perl 5.10.1 and am using the given/when statement. Here is the code:
#!/user/bin/perl print("Enter 1 for C to F or 2 for F to C"); $choice=<>; given($choice);{ when(1){ print( "Enter Temp in C "); $c=<>; $g = (9/5) * $c + 32; print ("Temp in Farenhite is: $g"); } when(2){ print ("Enter Temp in F: "); $f=<>; $h = (5/9)* ($f - 32); print ("Temp in Celsius Is: $h"); } default { print ("ERROR! input must be a 1 or 2"); } Here is the terminal output:
owner@owner-desktop:~/PERL-LAB$ perl temp.pl syntax error at temp.pl line 5, near "){" syntax error at temp.pl line 10, near "){" syntax error at temp.pl line 14, near "}" Execution of temp.pl aborted due to compilation errors. owner@owner-desktop:~/PERL-LAB$ I guess it is something simple, but I'm a bit rusty with perl right now and I can't see it. This is my first time programming with given/when also. Any help would be greatly appreciated and then I can move on and program a MS Word Killer! Paul
|