http://www.perlmonks.org?node_id=917726


in reply to Re^3: File::Glob infinate loop with while loop unlike core glob function
in thread File::Glob infinite loop with while loop unlike core glob function

When I look at File::Glob, I don't see it promising to do "while magic".

I never claimed it promised to do while magic, surely you can see that.

You can also see that there no magic involved (just wantarray) if you UTSL, GLOB_NOMAGIC option notwithstanding.

 

and it is not "trivial" to modify that behavior now.

When I used "trivial" , it was obvious I was talking about the effort (copy/paste) and not the politics;

But yes, even the politics are "trivial" because File::Glob is a module, it already changes behaviour , it can do so again

Cwd/File::Spec have changed behavior since 5.6.0, so can File::Glob; it doesn't have to live in CORE, it can become dual-lived like Cwd

 

That could break existing code, and the porters are notoriously (and justifiably) reluctant to do that.

If fixing an oversight breaks existing code, its worth any potential fallout

It doesn't even have to break existing code, just make it do the right thing via ':globDWIM' or ':globwantarray' or ':globscalar' .. whatever tag makes most sense

And AFAIC :) code that relies on the existing behaviour of a-list-in-scalar-context is unimportant and/or already broken ;) so it won't be affected much by a change :D

  • Comment on Re^4: File::Glob infinate loop with while loop unlike core glob function

Replies are listed 'Best First'.
Re^5: File::Glob infinate loop with while loop unlike core glob function
by jpl (Monk) on Aug 01, 2011 at 13:55 UTC
    The more I look at this, the more I'm coming around to your point of view. When I look at

    ext/File-Glob/t/global.t

    they appear to be doing extensive testing to make sure a glob overload behaves in the same way as the core glob, including loops using <> and explicit invocations of glob. If I modify global.t as follows

    4,5c4 < chdir 't' if -d 't'; < @INC = '../lib'; --- > chdir '/home/jpl/src/perl-5.14.1/t'; 94a94,111 > > @s = (); > while (glob("/tmp/dir with spaces/*")) { > push @s, $_; > last if (@s > 1000); > } > print(scalar(@s), "\n"); > print(join(" ", @s), "\n"); > > package Bar; > use File::Glob ':glob'; > @s = (); > while (glob("/tmp/dir with spaces/*")) { > push @s, $_; > last if (@s > 1000); > } > print(scalar(@s), "\n"); > # print(join(" ", @s), "\n");
    I get
    2 /tmp/dir with 1001
    at the end of the output (the directory has 3 entries). It's above my pay grade to figure out why this happens, or how to make the replacement using :glob behave as core glob does, but I'm running out of arguments why the current behavior is correct. Your suggestion of a new tag to get this behavior seems reasonable.
Re^5: File::Glob infinate loop with while loop unlike core glob function
by jpl (Monk) on Aug 01, 2011 at 10:45 UTC
    You can also see that there no magic involved (just wantarray) if you UTSL, GLOB_NOMAGIC option notwithstanding.
    The "magic" is not in detecting the context in which you are invoked, it is in returning different scalar values when invoked with the same argument. This is not your math teacher's concept of a function. If you run this
    #!/usr/bin/perl -w use strict; use feature 'say'; say scalar(glob('*')); say scalar(glob('*')); say scalar(glob('*')) for (1..2);
    in a directory with more than one file, you'll get the same file, twice, then the same file and a different one. There's obviously some "hidden state" beyond scalar context. I choose to call this "magic", you can choose otherwise.