Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Sub calling sadness

by nefigah (Monk)
on Mar 08, 2008 at 07:29 UTC ( #672948=note: print w/replies, xml ) Need Help??

in reply to Re: Sub calling sadness
in thread Sub calling sadness

ok( ThatPackage::blah $foo, 'blah' ); means ok( ThatPackage::blah($foo, 'blah') );
Alright. Perl must fairly liberally interpret it sometimes; because it was working as ok( ThatPackage::blah($foo), 'blah' ) until $foo contained leading whitespace :( (I could tell because the ok() method was correctly printing out 'blah' as the test description)

I'm a peripheral visionary... I can see into the future, but just way off to the side.

Replies are listed 'Best First'.
Re^3: Sub calling sadness
by stiller (Friar) on Mar 08, 2008 at 07:52 UTC
    Update: I wrote the below, obviously after reading ikegami's answer above. Yet, I went on, totally wrong. The only problem with his answer was that it's a bit terse. When the sub you are calling eats the rest of the argument list, you get surprises. For example, look at print. It seems a litle silly that ok() is OK with only one argument, but it is, which hides the real problem in your code.
    sorry for confusing... (e.g.:disregard the rest of this post)

    It is not possible to explain the semantics of your code without access to the definition of ThatPackage. If you could include that definition, we could probably better explain what happens and why.

    For example, include your definition of ThatPackage::blah something like this (after verifying that it still demonstrates the problem):

    use Test::More 'no_plan'; #require ''; package ThatPackage; sub blah { return $_[0] =~ /hi/ }; # Does NOT demonstrate the problem package main; my $foo = "hi"; my $bar = " hi"; ok( ThatPackage::blah $foo, 'blah' ); ok( ThatPackage::blah $bar, 'blah2' ); ok( ThatPackage::blah($foo), 'blah3' ); ok( ThatPackage::blah($bar), 'blah4' );
      Fair enough, here it all is, shortened as short as possible:

      Contents of
      #!/usr/bin/env perl use warnings; use strict; use feature ':5.10'; package ThatPackage; sub parse { } # Yep, even empty the error occurs, because it never eve +n gets as far as calling it
      Contents of
      #!/usr/bin/env perl -w use feature ':5.10'; use Test::More 'no_plan'; require ''; my $foo = "blah"; my $bar = " blah"; ok( ThatPackage::parse $foo, " this is a test" ); # fine, test doesn't + pass but runs fine ok( ThatPackage::parse($bar), " this is a test" ); # also fine ok( ThatPackage::parse $bar, " this is a test" ); # error here: 'Can't + call method "ThatPackage::parse" without a package or object referen +ce at line 43.'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://672948]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2018-03-21 23:33 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (272 votes). Check out past polls.