> -----Original Message-----
> From: Elias Assmann [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 17, 2002 5:45 PM
> To: [EMAIL PROTECTED]
> Subject: Can't call method "foo" without a package or object reference
> at...
> 
> 
> Hello,
> 
> I ran into this strange error... What I got was this:
> 
> Can't call method "parse" without a package or object reference at
> ./calc.pl
>         line 60, <STDIN> line 1 (#1)
> 
> and from 'diagnostics':
> 
>     (F) You used the syntax of a method call, but the slot filled by
>     the object reference or package name contains an expression that
>     returns a defined value which is neither an object reference nor a
>     package name.
> 
> Now that didn't tell me anything at all :-) Because, you see, I just
> coudln't relate it to my code, the relevant line of which was simply:
> 
> @tok = parse $_;
> 
> I played around a bit with this and it seems that I get that error
> whenever I try to call a function which is declared only later on, and
> do it without parens around the arguments... That can't be right, can
> it?

Yes, it's right. Perl is interpreting this as the "indirect object
notation",
since it doesn't know that parse is a sub yet. To see how Perl is parsing
this,
run the following from your shell:

 $ perl -MO=Deparse -e '@tok = parse $_'
 @tok = $_->parse;        << This is how Perl sees your code

The error message is because $_ is not an object reference or a package
name,
so Perl can't figure out which parse method to call.

You can fix this by either:

1. Declare the sub by either moving its definition to the top of your file
or
adding a sub parse; line at the top of your file. Try this:

  $ perl -MO=Deparse -e 'sub parse; @tok = parse $_'
  sub parse {}
  @tok = parse($_);       << Now it's a function call

2. Use parentheses in all function calls. Then you don't have to worry about
where the sub is defined.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to