'glob' does not expand as I want

6 views
Skip to first unread message

gamo

unread,
Nov 1, 2021, 12:33:43 PM11/1/21
to
#!/usr/bin/perl -w

use 5.032; # hapens in 5.030 too

my @A= glob "{apple,tomato,cherry}={green,yellow,red}";
say "@A";

my $b1 = join(",", 1..1000);
my $b2 = join(",", "a".."z");

my @B = glob "{$b1}={$b2}";
my @C;
for (@B){
@C = split /=/;
say "@C";
}

exit 1;

__END__

This does not works as I expected because if I change 1000 by 10000
nothing is printed. Somewhere I reach an unexpected limit.

TIA

--
http://gamo.sdf-eu.org/
perl -E 'say "Error: figure it out. "'

Eli the Bearded

unread,
Nov 1, 2021, 2:53:06 PM11/1/21
to
In comp.lang.perl.misc, gamo <ga...@telecable.es> wrote:
> my $b1 = join(",", 1..1000);
> my $b2 = join(",", "a".."z");
>
> my @B = glob "{$b1}={$b2}";
> my @C;
> for (@B){
> @C = split /=/;
> say "@C";
> }
...
> This does not works as I expected because if I change 1000 by 10000
> nothing is printed. Somewhere I reach an unexpected limit.

Um, don't do that? The glob function is specifically for filenames
and using it in other ways I suspect is not well supported. I'm going
to guess your "unexpected limit" is the ARG_MAX value in limits.h.

perldoc -f glob says "see File::Glob" and perldoc File::Glob talks
about the various limits.

For your use case, that's fairly simple function to implement in pure
perl.

Elijah
------
has literally never used the glob function

gamo

unread,
Nov 2, 2021, 6:15:53 AM11/2/21
to
El 1/11/21 a las 19:53, Eli the Bearded escribió:
> Um, don't do that? The glob function is specifically for filenames
> and using it in other ways I suspect is not well supported. I'm going
> to guess your "unexpected limit" is the ARG_MAX value in limits.h.
>
> perldoc -f glob says "see File::Glob" and perldoc File::Glob talks
> about the various limits.
>
> For your use case, that's fairly simple function to implement in pure
> perl.

Thank you. Yes, a pair of 'for' would do the job,
but I was curious about that combinational feature.

--
http://gamo.sdf-eu.org/
perl -E 'say "Error: https not supported."'

Eric Pozharski

unread,
Nov 2, 2021, 6:33:20 AM11/2/21
to
with <eli$21110...@qaz.wtf> Eli the Bearded wrote:
> In comp.lang.perl.misc, gamo <ga...@telecable.es> wrote:

>> my $b1 = join(",", 1..1000);
>> my $b2 = join(",", "a".."z");
>>
>> my @B = glob "{$b1}={$b2}";
>> my @C;
>> for (@B){
>> @C = split /=/;
>> say "@C";
>> }
> ...
>> This does not works as I expected because if I change 1000 by 10000
>> nothing is printed. Somewhere I reach an unexpected limit.
>
> Um, don't do that? The glob function is specifically for filenames and
> using it in other ways I suspect is not well supported. I'm going to
> guess your "unexpected limit" is the ARG_MAX value in limits.h.

I disagree. Clearly, there are limits (check this, hilarious:)

perl -wE '
$aa=join",",1..1030;
$ab=join",","a".."z";
say glob "{$aa}={$ab}"'

but those limits are of "csh implementation in Perl". Unfortunately,
those are behind XS (IOW, too much trouble to look for, at the moment,
may be in a couple of months).

> perldoc -f glob says "see File::Glob" and perldoc File::Glob talks
> about the various limits.

Those are flags, except "GLOB_LIMIT". Aging zsh 4.3.17 just happily
expanded "{1..10000}={a-z}" (needs tweaking though) and happily passed it
to "command echo".

> For your use case, that's fairly simple function to implement in pure
> perl.

Totaly agree. Somehow I don't see it happening (I might be
over-pessimistic though).

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Otto J. Makela

unread,
Nov 2, 2021, 9:47:04 AM11/2/21
to
Eli the Bearded <*@eli.users.panix.com> wrote:

> In comp.lang.perl.misc, gamo <ga...@telecable.es> wrote:
>> my $b1 = join(",", 1..1000);
>> my $b2 = join(",", "a".."z");
>>
>> my @B = glob "{$b1}={$b2}";
>> my @C;
>> for (@B){
>> @C = split /=/;
>> say "@C";
>> }
> ...
>> This does not works as I expected because if I change 1000 by 10000
>> nothing is printed. Somewhere I reach an unexpected limit.
>
> Um, don't do that? The glob function is specifically for filenames
> and using it in other ways I suspect is not well supported. I'm going
> to guess your "unexpected limit" is the ARG_MAX value in limits.h.
>
> perldoc -f glob says "see File::Glob" and perldoc File::Glob talks
> about the various limits.

At least for my rather old v5.16.3 "perldoc -f glob" also says:

If non-empty braces are the only wildcard characters used in the
"glob", no filenames are matched, but potentially many strings
are returned. For example, this produces nine strings, one for
each pairing of fruits and colors:
@many = glob "{apple,tomato,cherry}={green,yellow,red}";

So "other ways" than filenames are at least minimally supported.
--
/* * * Otto J. Makela <o...@iki.fi> * * * * * * * * * */
/* Phone: +358 40 765 5772, ICBM: N 60 10' E 24 55' */
/* Mail: Mechelininkatu 26 B 27, FI-00100 Helsinki */
/* * * Computers Rule 01001111 01001011 * * * * * * */
Reply all
Reply to author
Forward
0 new messages