els instead of else 
Author Message
 els instead of else

I came across some interesting behavior after mis-typing 'else' as 'els'.
The script passed the syntax check but failed on execution.  Could someone
explain why the message below is generated instead of something like a
"bare word" message?


#!/usr/bin/perl -w
use strict;

if (1)
{
        print "one\n";

Quote:
}

els
{
        print "not one\n";

Quote:
}


els.pl syntax OK


one
not one
Can't call method "els" without a package or object reference at els.pl
line 9.


print "one\n";;
do { print "not one\n" }->els;
els.pl syntax OK

Thanks,
Bob



Sat, 25 Jan 2003 03:00:00 GMT  
 els instead of else

Quote:


> print "one\n";;
> do { print "not one\n" }->els;
> els.pl syntax OK

This is exactly what's going on.  Perl is thinking it's an instance
of the "indirect object" syntax, which is documented as being frought
with ambiguity.

        foo bar;

interpreted as

        bar->foo;

and

        foo { print "bar\n" };

interpreted as

        (do{ print "bar\n" })->foo;

--
John Porter



Sat, 25 Jan 2003 03:00:00 GMT  
 els instead of else

[snip]

Quote:
> Can't call method "els" without a package or object reference at els.pl
> line 9.


> print "one\n";;
> do { print "not one\n" }->els;
> els.pl syntax OK

[snip]

You had the right idea with using Deparse, and it is giving you the
answer, it's just not very easy to interpret.

This is an indirect object method call:

Method Object Argument(s);

As opposed to the more common:

Object->Method(Arguments);

The extra-confusing part is that the indirect object syntax allows for
a BLOCK returning Object in place of Object.  That is how you cascade
object calls:

Method2 { Method1 Object Argument(s) } Argument(s);

For more detail, see "perldoc perlobj".

--
Ren Maddox



Sat, 25 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. BLOB fields! What are they really?

2. els

3. Why use Sys::Hostname instead of just $ENV{SERVER_NAME}

4. Perlmenu over cterm instead of cursesperl?

5. Perl instead of DOS batch files?

6. What to use instead of php

7. making CGI output to a file instead of a browser

8. Tk::BrowseEntry - Return index instead of value?

9. Using Perl instead of VBA in Excel

10. REQ: bytewise string manipulation C style instead of substr

11. Perl daemon server instead of inetd process - code

12. Editing RTF docs with Perl/AWK instead of WordBASIC

 

 
Powered by phpBB® Forum Software