LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-27-2006, 11:09 AM   #1
tekmann33
Member
 
Registered: Nov 2006
Posts: 188

Rep: Reputation: 30
Bad switch statement (problem in the code block?)


I am writing a perl script that will take the day of the week and based on that day, assign a label to a backup tape for eventual backup procedures.

I only have a portion of the code written, but I am getting syntax errors with my case statement.

I am using perl version 5.8.8 on a Fedora 6 system.

Here is my code:

1 #!/usr/bin/perl
2 use Switch;
3
4
5 my $day = `date +%a`;
6 my $tape_label;
7
8 print $day;
9
10 switch ($day) (
11 case ('Mon') {$tape_label = 'ISD001';}
12 case ('Tue') {$tape_label = 'ISD002';}
13 case ('Wed') {$tape_label = 'ISD003';}
14 case ('Thur') {$tape_label = 'ISD004';}
15 case ('Fri') {$tape_label = 'ISD005';}
16 case ('Sat') {$tape_label = 'ISD006';}
17 case ('Sun') {$tape_label = 'ISD007';}
18
19 )
20
21 #Switch statement to determine what to label the tape
22
23 #Execute the following system commands
24
25 #mt -f /dev/rmt/0 rewind
26 #cd /opt/openv/netbackup/bin/admincmd
27 #./bpexpdate -d 0 -m (tape variable)
28
29 #There is a prompt here to erase the tape, might need to capture this variable
30 #If yes ...procedd, no quit
31
32 #mt -f /dev/rmt/0 erase
33 #./bplabel -m (tape variable) -d 4mm -n HPC5683A0
34



I check for syntax errors at this point and receive this:

[root@BriansFC bclanton]# perl -c perltest.pl
Bad switch statement (problem in the code block?) near perltest.pl line 10


I comment out all the case statements within the code block, save it, and still get the same error:

1 #!/usr/bin/perl
2 use Switch;
3
4
5 my $day = `date +%a`;
6 my $tape_label;
7
8 print $day;
9
10 switch ($day) (
11 /* case ('Mon') {$tape_label = 'ISD001';}
12 case ('Tue') {$tape_label = 'ISD002';}
13 case ('Wed') {$tape_label = 'ISD003';}
14 case ('Thur') {$tape_label = 'ISD004';}
15 case ('Fri') {$tape_label = 'ISD005';}
16 case ('Sat') {$tape_label = 'ISD006';}
17 case ('Sun') {$tape_label = 'ISD007';}
18 */
19 )
20
21 #Switch statement to determine what to label the tape
22
23 #Execute the following system commands
24
25 #mt -f /dev/rmt/0 rewind
26 #cd /opt/openv/netbackup/bin/admincmd
27 #./bpexpdate -d 0 -m (tape variable)
28
29 #There is a prompt here to erase the tape, might need to capture this variable
30 #If yes ...procedd, no quit
31
32 #mt -f /dev/rmt/0 erase
33 #./bplabel -m (tape variable) -d 4mm -n HPC5683A0
34
35
36
37
38
39
[root@BriansFC bclanton]# perl -c perltest.pl
Bad switch statement (problem in the code block?) near perltest.pl line 10


I am using examples to check for syntax in the book "Perl for Dummies" and I do not see what I am doing wrong syntax wise.

Any input would be much appreciated.
 
Old 12-27-2006, 11:30 AM   #2
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 23, 24, RHL 5.2
Posts: 560

Rep: Reputation: 56
It looks like you should have a brace { instead of parenthesis ( on lines 10 and 19 to start and finish the block of code for the switch.
Code:
10 switch ($day) {
11 case ('Mon') {$tape_label = 'ISD001';}
12 case ('Tue') {$tape_label = 'ISD002';}
13 case ('Wed') {$tape_label = 'ISD003';}
14 case ('Thur') {$tape_label = 'ISD004';}
15 case ('Fri') {$tape_label = 'ISD005';}
16 case ('Sat') {$tape_label = 'ISD006';}
17 case ('Sun') {$tape_label = 'ISD007';}
18 
19 }
Bill
 
Old 12-27-2006, 11:53 AM   #3
tekmann33
Member
 
Registered: Nov 2006
Posts: 188

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by wmakowski
It looks like you should have a brace { instead of parenthesis ( on lines 10 and 19 to start and finish the block of code for the switch.
Code:
10 switch ($day) {
11 case ('Mon') {$tape_label = 'ISD001';}
12 case ('Tue') {$tape_label = 'ISD002';}
13 case ('Wed') {$tape_label = 'ISD003';}
14 case ('Thur') {$tape_label = 'ISD004';}
15 case ('Fri') {$tape_label = 'ISD005';}
16 case ('Sat') {$tape_label = 'ISD006';}
17 case ('Sun') {$tape_label = 'ISD007';}
18 
19 }
Bill

That was it...I just couldn't see it. Thanks a bunch!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
a string switch statement in c++ pengu Programming 14 02-25-2006 09:58 PM
Switch statement on strings in structures? Mistro116@yahoo.com Programming 2 11-13-2005 07:18 PM
how to close 'else' statement block in bash script servnov Linux - General 9 11-12-2004 03:53 PM
Bad switch statement (problem in the code block?) nifflerX Linux - General 2 07-14-2004 03:45 PM
switch statement linuxanswer Programming 2 11-29-2003 11:25 PM


All times are GMT -5. The time now is 03:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration