consider 'blah.pl'
and data file 'a'#!/usr/bin/perl use strict; sub screwed { my ($in) = @_; open(IN, "<$in"); while(<IN>) { print "file $in contains $_"; } close(IN); } my @instances = ("a", "b"); map { print "before $_\n" } @instances; map { screwed "$_"; } @instances; map { print "after $_\n" } @instances;
and data file 'b'a1 a2
running this i getb1 b2
what has happened to the entries of instances? they are there but are empty (null?)before a before b file a contains a1 file a contains a2 file b contains b1 file b contains b2 after after
if i remove the while (<IN>) line i get what i expect...
so why does iterating over the <IN> with a while kill my instances list?!! i don't get it...before a before b opening file named a opening file named b after a after b
was getting this with a suse7 locally built perl5.6 and thinking it was (maybe) a perl bug i rebuily perl5.8.0 locally and am still getting it.. :( mat
In reply to opening a file destroys nulling entries in a list?!?! by matpalm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |