Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to fix the new line matching in Perl


This is the line I try ot capture:

                Submit fileCRLF
        ===========================CRLF

Open in new window


or

		Submit fileLF
	===========================LF

Open in new window



However these matches does not work due to the new line character. I think the match should be more smart at this point.

I would like to cover Windows, Unix and Mac systems.

if (/^\s*Submit\s+file\s*$/)

Open in new window



if (/^\s*\=+\s*$/)

Open in new window


How can I fix this problem in my code?

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I meant to say that the relevant line for what you want is line 10.
Those regexes should work.  What exactly are you seeing or not seeing?  Have you checked the value of $_ prior to calling the regex to ensure that the value you expect is in that variable?
Avatar of Tolgar
Tolgar

ASKER

I assume this will take care of the equal line

if (m{^\s*=+\s*[\r\n]+}) {
print "got line $_\n";
}

Open in new window


Am I right?

Thanks,

Yes, that will take care of the equal line.

Although, I just did some quick checks based on bounsy's comment and it looks like the regexes as you had them originally should work (they work correctly under Cygwin perl 5.10.1 with dos/unix/mac at least).  Specifically, I used m{^\s*Submit\s+file\s*$} and it matched.

Also, have you tried using chomp on $_ prior to doing the match (shouldn't be necessary but should also fix any end-of-line problems (I think)).

Hmm.  I suppose the problem could come in if the file is in one format but perl (or the OS) think it's in a different format.  I just checked and "unix" format with dos eol seems to work but mac eol does not (I didn't test other combinations).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial