in reply to Re^2: 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
You can't attach files, but you can include the contents of text files in your reply by putting the text in code tags. Please though keep the size of such samples small - just enough to demonstrate the issue. Often that will mean creating suitable sample data (perhaps by trimming down a real file).
I'd write that as:
given($answer) { when ('1') {error_entry();} when ('2') {warning_entry();} default {die "Expected 1 or 2 for the answer. Got $answer\n";} }
Using a regex match would match on any answer containing a 1 digit for the first case and any answer containing a 2 digit for the second case. Maybe not a problem for your application, but as a general thing you should validate data and handle unexpected data in some appropriate fashion. die is most appropriate for production code when you are using it to throw exceptions that are caught by eval. Generally it is much better to die and have it handled (or not in which case to script does die) than to carry on processing bogus data.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Why is my script not printing anything?and how to add a switch case in perl
by iphone (Beadle) on Dec 02, 2010 at 05:09 UTC | |
by GrandFather (Saint) on Dec 02, 2010 at 06:03 UTC | |
by iphone (Beadle) on Dec 02, 2010 at 07:23 UTC | |
by cdarke (Prior) on Dec 02, 2010 at 09:11 UTC | |
by GrandFather (Saint) on Dec 02, 2010 at 10:05 UTC | |
by pemungkah (Priest) on Dec 02, 2010 at 23:42 UTC |