In addition, I've been playing around with the 'use diagnostics' feature in perl.  
That's in addition to 'use warnings'.  I don't recommend it for regular coding but 
when stumped it may help.



> On Feb 19, 2004, at 3:14 PM, Anthony Vanelverdinghe wrote:
> 
> > Hi
> 
> Howdy.
> 
> > Could anyone please tell me what's wrong with the following "program"?
> 
> I'll try.
> 
> > The compiler gives errors in the switch statement.
> 
> Perl doesn't have a native switch statement, but it is included as a 
> module in 5.8+
> 
> > Thx!!
> >  Anthony
> 
> First, things missing are right here:
> 
> #!/usr/bin/perl
> 
> use strict;                   # play by the good coder rules
> use warnings;         # helps us help you
> 
> use Switch;           # request the switch module
> 
> > %commands=('v',0,'w',1,'t',2,'/pattern/',3,'s',4,'x',5);
> 
> Then you'll need:
> 
> my %commands = ('v',0,'w',1,'t',2,'/pattern/',3,'s',4,'x',5); # to 
> satisfy 'strict'
> 
> > $end = 0;
> 
> my $end = 0;
> 
> > while (!end){
> 
> I believe that's supposed to be:
> 
> while ( ! $end ) {    # note $
> 
> > print "bookmarks.html>";
> > $operation = <>;
> > chop $operation;
> 
> Don't use chop(), use chomp().  You can even do it in one line, 
> replacing the two above with:
> 
> chomp(my $operation = <>);
> 

> > $op=$commands{$operation};
> > switch ($op) {
> 
> switch ($commands{$operation) {
> 
> >    case 0 {
> >            &add ();
> 
> Don't call subs like that.  Just use:
> 
> add();
> 
> >            last;}
> >    case 1 {
> >            &delete();
> >            last;}
> >    case 2 {
> >            &show();
> >            last;}
> >    case 3 {
> >            &pattern();
> >            last;}
> >    case 4 {
> >            &save();
> >            last;}
> >    case 5 {
> >            &exit ();
> >            last;}
> > }
> > }
> >
> >
> >
> >
> > sub add{
> >    print "add";
> > }
> >
> > sub delete{
> >    print "delete";
> > }
> >
> > sub show{
> >    print "show";
> > }
> >
> > sub pattern{
> >    print "pattern";
> > }
> >
> > sub save{
> >    print "save";
> > }
> >
> > sub exit{
> >    $end = 1;
> > }
> 
> See if that gets you going.
> 
> James
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to