Re: how do prlglobs expand (was Re: 'nobody' using sudo -- scary!)



[please quote properly]

Quoth news1234@xxxxxxx:

What would happen if I use follwing statement in perl"

foreach my $file (</home/*/.forward>){
do_something($file);
}

would perl
- iterate through the files
- or would perl first create a list of all the files and then
iterate through them.

'foreach' always creates a list and then iterates over it.

- or would it hit a linit and not provide all hits.
- or does it depend on the system perl is running on

You will eventually hit the memory limit on your system, and the limit
on the size of the pointer used to index the perl stack; you won't hit
any limits before that.

You can avoid pre-creating the list by using 'while' instead:

while (my $file = </home/*/.forward>) {
...
}

Ben

--
For far more marvellous is the truth than any artists of the past imagined!
Why do the poets of the present not speak of it? What men are poets who can
speak of Jupiter if he were like a man, but if he is an immense spinning
sphere of methane and ammonia must be silent? [Feynmann] ben@xxxxxxxxxxxx
.



Relevant Pages

  • Re: how do prlglobs expand (was Re: nobody using sudo -- scary!)
    ... What would happen if I use follwing statement in perl" ... iterate through them. ... in the case of foreach. ... For example, if I put a "last" in the while loop, the code still performed ...
    (comp.lang.perl.misc)
  • Re: RSS feeds and HTML special characters
    ... However, when I go to use the string from within Perl, I get a Warning, ... you need to be using perl 5.8. ... Why do the poets of the present not speak of it? ...
    (comp.lang.perl.misc)
  • Re: double slash operator syntax question
    ... It's in 5.8.8 or my perl is lying. ... ports perl applies the dor patch by ... Why do the poets of the present not speak of it? ...
    (comp.lang.perl.misc)
  • Re: [OT] Javascript "for in"
    ... If you use an object to iterate over, ... never be sure if you're actually iterating over an array. ... close to Perl, funnily enough. ... the fact that objects are merely hashes of properties felt very ...
    (comp.lang.perl.misc)
  • Re: how to find the path of the file
    ... I have a perl file called abc.pl and when i run it i want it to print ... Why do the poets of the present not speak of it? ... $Script - basename of script from which perl was invoked ...
    (comp.lang.perl.misc)