Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Overloading Weirdness

by Athanasius (Archbishop)
on Jun 23, 2018 at 07:12 UTC ( #1217270=note: print w/replies, xml ) Need Help??


in reply to Overloading Weirdness

Hello pudge,

I tried separating your str package into its own module/file, and then useing it in the main script:

use strict; use warnings; use 5.010; use Data::Dumper; $Data::Dumper::Sortkeys = 1; use lib qw(.); use str; ...

The output may be closer to what you were wanting (if I’ve understood correctly):

$VAR1 = { 'BAD' => [ bless( [ bless( [ 'a ', bless( do{\(my $o = 'foo')}, 's +tr' ) ], 'str' ), ' a' ], 'str' ), bless( [ bless( [ $VAR1->{'BAD'}[0][0][1], ' ' ], 'str' ), bless( do{\(my $o = 'bar')}, 'str' ) ], 'str' ), bless( [ bless( [ bless( [ bless( [ 'a ', $VAR1->{'BAD' +}[0][0][1] ], 'str' ), ' a ' ], 'str' ), $VAR1->{'BAD'}[1][1] ], 'str' ), ' a' ], 'str' ) ], 'GOOD' => [ bless( [ bless( [ $VAR1->{'BAD'}[0][0][1], ' ' ], 'str' ), $VAR1->{'BAD'}[1][1] ], 'str' ), $VAR1->{'GOOD'}[0], bless( [ $VAR1->{'BAD'}[0][0][1], ' a' ], 'str' ) ] }; $VAR1 = { 'BAD_GOOD' => [ bless( [ '', bless( [ bless( [ 'a ', bless( do{\(my $o + = 'foo')}, 'str' ) ], 'str' ), ' a' ], 'str' ) ], 'str' ), bless( [ '', bless( [ bless( [ $VAR1->{'BAD_GOOD +'}[0][1][0][1], ' ' ], 'str' ), bless( do{\(my $o = 'bar') +}, 'str' ) ], 'str' ) ], 'str' ), bless( [ '', bless( [ bless( [ bless( [ bless( [ + 'a ', + $VAR1->{'BAD_GOOD'}[0][1][0][1] ] +, 'str' ), ' a ' ], 'str' ) +, $VAR1->{'BAD_GOOD +'}[1][1][1] ], 'str' ), ' a' ], 'str' ) ], 'str' ) ] }; 17:03 >

I don’t pretend to know exactly what’s going on (I have the ’flu, my head is more than usually woolly), but perhaps this will help you towards a solution.

Cheers,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Overloading Weirdness
by ikegami (Patriarch) on Jun 23, 2018 at 15:31 UTC

    "." means the current work directory, not the script's directory.

    use lib qw(.);
    should be
    use FindBin qw( $RealBin ); use lib $RealBin;

      Hello ikegami,

      Thanks for that! I had a hard time trying to think of a situation in which the current working directory would be different to the script’s directory (in the absence of explicit calls to chdir, of course). Finally, the penny dropped: if I invoke a script foo/bar/baz.pl from the foo directory:

      perl bar/baz.pl

      the script’s directory is foo/bar, but the current working directory is still foo!

      Thanks again,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        Yes, relpath/prog[1] and /abspath/prog[2], but even just prog[3]

        1. If relpath doesn't refer to the CWD.
        2. If /abspath doesn't refer to the CWD.
        3. If the $PATH entry used doesn't refer to the CWD.
      Regardless, if the difference is that the class is in a separate file, that would be super weird.
Re^2: Overloading Weirdness
by pudge (Sexton) on Jun 23, 2018 at 15:01 UTC
    What version of perl is that? I saw no difference whether it was in a separate file. Thanks!

      I was using Strawberry Perl 5.26.0 (64-bit), but I get the same result on my various Strawberry Perls going back to 5.10.1 (32-bit).

      It occurred to me to try keeping the str package in the same file as the main code, but moving it to the top of the file:

      package str; ... sub concat { ... } package main; use strict; use warnings; ...

      And the output is the same as was obtained by moving the str package into a separate file. So the issue is (I think) not whether str is in a separate file, but whether it’s “visible” to the Perl compiler when the main code is parsed.

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        I see no difference in any perl by moving it to the top of the file, or to a different file. I can't see why it would make a difference, and I do not see that it does make a difference. Odd. Even though you're using Windows, I don't know why the behavior would be different.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1217270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2022-01-18 07:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (52 votes). Check out past polls.

    Notices?