Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: @INC order not followed

by Fletch (Bishop)
on Oct 19, 2022 at 03:25 UTC ( [id://11147509]=note: print w/replies, xml ) Need Help??


in reply to @INC order not followed

As it says those two lines are the contents of an eval done at line 114 from Text::CSV (which it appears you have a very slightly behind copy; in the latest that call has moved a few lines). The perldebug docs for f say that if you don't give it a full path the argument is taken as a regex which it searches for in the keys for %main::. If something else pulled in Text::CSV and it ran its eval and that happens to be the first match for qr{^_<.*CSV} as the keys happen to be ordered then that's what it'll switch to. Has nothing to do with @INC not being honoured.

Edit: the guts of the f command's search (5.34.0 version):

# if not in magic file list, try a close match. if ( !defined $main::{ '_<' . $file } ) { if ( ($try) = grep( m#^_<.*$file#, keys %main:: ) ) { { $try = substr( $try, 2 ); print $OUT "Choosing $try matching '$file':\n"; $file = $try; } } ## end if (($try) = grep(m#^_<.*$file#... } ## end if (!defined $main::{ ...

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: @INC order not followed
by misterperl (Pilgrim) on Oct 19, 2022 at 13:08 UTC
    Ahh yes that does make sense, EXCEPT why did the f yield a 2-line file? f is supposed to match on filenames I thought- not grep into files? Why didnt it show me ALL of Text::CSV.pm ?

    I learned something here that f doesn't find the first match in @INC order- it finds a random match on eval of the regex? Seems odd NOT to yield match 1 in @INC since that's how Perl will run the files so it would make sense to go to THAT file I would think. Also in the past it went to MY CSV which I guess was just luck.

    TYVM!

      Because that's not what matched on when it searched for qr/CSV/ on the entire list of loaded "file" names. When you (string?) eval something it stubs in a representation of the location of the eval call and its showing you just the text that got eval'd there.

      And again @INC and its ordering doesn't have anything to do with the order keys returns things for the %main:: stash ( a hash, but it's a special hash). If you have %foo = qw( 2 a 22 b 222 c ) then you similarly can't say what (grep /2/, keys %h)[0] is going to wind up returning.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

      Please note that to list a file after you have chosen it with f, you need to use l to list one "page" at a time (more on that can be found in the debugger's help interface -- you will want to h to get the general overview of possible commands, and h l to get more help on l specifically; v might also be of use).

      Caveat: I am not a debugger expert. I actually learned this earlier today when I read your post, and then started playing around in the debugger to replicate. But I knew other monks were much better at the debugger than I, and could explain the f portion of your difficulty, whereas I couldn't. I waited until I read good explanations of that part, but since no one else explained how to see the contents of the file, I thought I'd now share what I learned, one debugger-newb to another.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found