At this point I feel compelled to mention that if the file you will be working on is more than a few K or so, then it might be a good idea to rewrite your loop so that you don't dump the entire file to memory. Something like:
open(FILE,"myfile.txt"); while(<FILE>){ if($_ =~ /Date:/){ print "Ok!\n"; DoSomeOtherStuff(); } } Which you'll notice is already being done in some form in a few of the responses. -----Original Message----- From: Shishir K. Singh [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 05, 2002 1:48 PM To: Eric Beaudoin Cc: Ankit Gupta; [EMAIL PROTECTED] Subject: RE: Help in Regular expression with array Beau..I guess , the evaluation of the expression is not going to be true if no "Date:" is found. Since map returns a list consisting of the results of each successive evaluation of the expression..., the map will return undef. Although, here..I think using grep would be a better idea!! -----Original Message----- From: Eric Beaudoin [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 05, 2002 4:29 PM To: Shishir K. Singh Cc: Ankit Gupta; [EMAIL PROTECTED] Subject: RE: Help in Regular expression with array At 16:12 2002.06.05, Shishir K. Singh wrote: >open (FILE , "<$ARGV[0]"); >print "ok" if ( map { /Date:/ } (<FILE>) ); >close FILE; map return an array with the result of the express apply to each line. Even if none of the lines in <FILE> contain Date:, you will have an array with one "" value for each line. This is a non empty array i.e. it has multiple lines and when evaluate in a scalar context (with the if() ), it would always be true unless there are no lines in <FILE>. I think you want grep there as in print "ok" if (grep /Date:/ ,(<FILE>)); or print "ok" if (map { /Date:/ ? $_ : () } , (<FILE>)); I may be wrong though. Best ---------------------------------------------------------- Éric Beaudoin <mailto:[EMAIL PROTECTED]> -- 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]