in reply to Re^4: Why is my script not printing anything?and how to add a switch case in perl
in thread Why is my script not printing anything?and how to add a switch case in perl

No! Those features require Perl 5.10 or later. For earlier versions of Perl you should use a cascade of if/elsif statements.

True laziness is hard work
  • Comment on Re^5: Why is my script not printing anything?and how to add a switch case in perl

Replies are listed 'Best First'.
Re^6: Why is my script not printing anything?and how to add a switch case in perl
by iphone (Beadle) on Dec 02, 2010 at 07:23 UTC

    Can i use something like below?

    if($answer) error_entry(); else warning_entry();
      No, you need the braces, and each time you don't indent a kitten dies:
      if ($answer) { error_entry(); } else { warning_entry(); }

      That is about half way between C and Perl. Even if you add the missing pairs of {} to turn that into Perl, it's still not really what you want probably. The equivalent of the code I gave above would be more like:

      if ($answer eq '1') { error_entry (); } elsif ($answer eq '2') { warning_entry (); } else { die "Expected 1 or 2 for the answer. Got $answer\n"; }

      It bothers me that correct basic syntax doesn't flow off your finger tips. Is this because you are new to Perl and are recycling code from other places, or are more familiar with a different language and are just coming up to speed with Perl or is there some other reason? We may be able to recommend tutorial material or suitable books if any of these cases apply.

      True laziness is hard work