Try eq instead of == (you want string, not numeric comparison)
On Fri, Dec 20, 2013 at 10:39 AM, john boris <jbori...@gmail.com> wrote: > I have this perl script that I have a long if/elsif portion. I am porting > a shell script to perl so I am trying to mimic a case statement from a > shell script. I know I should use Switch but the version of PERL I am using > (a bit old) and have to stay at the version does not have the switch.pmin > cpan. I would have to compile it myself, which I don't want to do. > I don't get any errors when it runs but the logic is not working. It will > only evaluate the first if statement. Here is the snippet: > > #Okay lets setup the school variable > #For sanity lets make sure we got the correct variable from the script > print "$ARGV[0]\n"; #this prints the correct variable > if ($ARGV[0] == "rc") {$school = "rc"} #This line is the only line > evaluated. I always get this value > elsif ($ARGV[0] == "bp") {$school = "bp";} > elsif ($ARGV[0] == "ac") {$school = "ac";} > elsif ($ARGV[0] == "ce") {$school = "ce";} > elsif ($ARGV[0] == "ng") {$school = "ng";} > elsif ($ARGV[0] == "jh") {$school = "jh";} > elsif ($ARGV[0] == "hu") {$school = "hu";} > elsif ($ARGV[0] == "fj") {$school = "fj";} > elsif ($ARGV[0] == "lc") {$school = "lc";} > elsif ($ARGV[0] == "lf") {$school = "lf";} > elsif ($ARGV[0] == "md") {$school = "md";} > elsif ($ARGV[0] == "oh") {$school = "oh";} > elsif ($ARGV[0] == "ar") {$school = "ar";} > elsif ($ARGV[0] == "sh") {$school = "sh";} > elsif ($ARGV[0] == "wc") {$school = "wc";} > elsif ($ARGV[0] == "aw") {$school = "aw";} > elsif ($ARGV[0] == "jc") {$school = "jc";} > elsif($ARGV[0] == "jp") {$school = "jp";} > > #Some lines snipped out > print "For the Week starting $dates[0]\n "; > print "This week $school had $admissions Admissions and $withdraws > Withdrawals.\n"; > print "Year to date $school had $ytodadmit Admissions and $ytodwdraw > Withdrawals.\n"; > print "$school:$admissions:$withdraws:$ytodadmit:$ytodwdraw\n"; > > #End of script > > I get this output > > oh #<-This value is correct > For the Week starting 12162013 > This week rc had 0 Admissions and 2 Withdrawals. > Year to date rc had 81 Admissions and 117 Withdrawals. > rc: 0: 2: 81: 117 > > > The rc should be oh. So I have the logic wrong or maybe you can't do what > I want with if/elsif statements. The two character in the if/elsif snippet > is going to be changed to a full name. I have it at 2 characters right now > for brevity while I debug this portion. > > > Thanks in Advance > -- > John J. Boris, Sr. > Online Services > www.onlinesvc.com > > _______________________________________________ > Tech mailing list > Tech@lists.lopsa.org > https://lists.lopsa.org/cgi-bin/mailman/listinfo/tech > This list provided by the League of Professional System Administrators > http://lopsa.org/ > >
_______________________________________________ Tech mailing list Tech@lists.lopsa.org https://lists.lopsa.org/cgi-bin/mailman/listinfo/tech This list provided by the League of Professional System Administrators http://lopsa.org/