On 10/28/09 Wed Oct 28, 2009 10:43 AM, "Harry Putnam" <rea...@newsguy.com> scribbled:
> Jim Gibson <jimsgib...@gmail.com> writes: > >> We need to know what you are trying to accomplish here. > > Its over 300 lines of code at this writing. Well we definitely do not want to see all 300 lines. However, some sample input data and the actual regular expressions you are using would help, along with the output you would like to get. > > Where the re come in: > > The program searches only headers for a given RE, but it also returns > the date line in any messages where the RE hits pay dirt. > > The search RE is set from the command line.. if it should happen to be > an RE looking for a specific date then two date lines would be output > for each message with a hit, since the DATE line is returned by > default anyway. > > So I tried to setup a test to avoid collecting the default DATE line > if the command line regex matched the default Date regex. > > So: > > if (cmdline_re NOT match Default DATE_re){ > then go ahead and collect the date line for later print > } You don't need to compare regular expressions. If you did, then you would use the 'eq' operator on the strings that generate the regular expressions. However, that is unreliable, as two strings can generate the same effective pattern, as, for example, 'a?' is equivalent to 'a{0,1}'. You should use the OR logical operator on the results from matching the input string against the two regular expressions: if( $line =~ /$date_re/ || $line =~ /$other_re/ ) { print $line; # or collect for later use } Or, if there are many more possible regular expressions to try, set a flag for each input line if any pattern matches, and use the value of the flag to determine further action on that line. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/