If you changed: foreach my $i (@array) {if ($i=~/something/) {print "$i\n"; } } to foreach (@array) # defaults to $_ {if ( /something/) {print "$_\n"; } }
Then use while while (<FH>) # defaults to $_ {if ( /something/) {print "$_\n"; } } Same processing, but one uses array while other uses a file. Wags ;) -----Original Message----- From: Teresa Raymond [mailto:[EMAIL PROTECTED]] Sent: Friday, May 03, 2002 09:18 To: Perl Beginners List Subject: @array=<FH> Someone mentioned that sucking a file into an array is not a good idea and I read the Perl fact on it but still am not sure why this is not a good idea, especially because a lot of code posted uses this method. In addition, if you have the file in an array then you can do foreach: open(FH, "text.fil") || die "Can't open text.fil\n"; my @array=<FH>; close(FH); foreach my $i (@array) {if ($i=~/something/) {print "$i\n"; } } Would one use while instead and what would the code look like? open(FH, "text.fil") || die "Can't open text.fil\n"; while (<FH>) {if (????what goes here to emulate the above foreach????) {print "????ditto????\n"; } } close(FH); -- ------------------------------- - Teresa Raymond - - Mariposa Net - - http://www.mariposanet.com - ------------------------------- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]