delorie.com/archives/browse.cgi | search |
X-Spam-Check-By: | sourceware.org |
To: | cygwin AT cygwin DOT com |
From: | Andrew DeFaria <Andrew AT DeFaria DOT com> |
Subject: | Re: Perl: Carriage Return??? |
Date: | Sat, 28 Apr 2007 09:39:49 -0500 |
Lines: | 53 |
Message-ID: | <f0vmbm$922$1@sea.gmane.org> |
References: | <679468866 AT web DOT de> |
Mime-Version: | 1.0 |
User-Agent: | Thunderbird 2.0.0.0 (Windows/20070326) |
In-Reply-To: | <679468866@web.de> |
X-IsSubscribed: | yes |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Unsubscribe: | <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Alexander Konig wrote: > Hello > > I am reading O´Reillly´s "Learning Perl" Book and doing the exercises. > My version of a test script for regular expression was : > > ? > while( <INPUT> ){ > chomp; > if( /$pattern/ ){ > print "\nHit: |$`>$&<$'|"; > } > else{ > if( !$option ){ > print "\n\nNo Hit >$pattern< in >$_< !"; > } > } > } > ? > > The output for this code is : > < !Hit >fred< in >Frederic > > < !Hit >fred< in >Mr.Smith > |it: |Nar>fred< > > I cannot imagine what is going wrong with that. Why some parts are > just overwritten. > The same code using Active Perl works. Some weeks ago this script has > worked using Cygwin, too. > Then, I wanted to check a regular expression with this script I had to > see this weird output. > > Could please someone help me. I really love working with Cygwin when > using Windows. Learn to use the Perl debugger. It's invaluable and teaches you how Perl works internally as you learn it more. Here's a cheat sheet: https://defaria.com/blogs/Status/archives/000582.html Given the above I would do perl -d <your script> then I would have (c)ontinued to the first if statement and used x $_ to dump out the contents that variable and probably would have noticed the extra line feed in that variable. That would have led me to the realization that DOS style files have both CRs and LFs and that Cygwin's Perl, being more Unix like than DOS like, only deals with LFs. One solution to this is to: chomp; chop if /\r/; Which will chomp the CR (\n) and chop off the LF (\r) if there is one. -- Andrew DeFaria <http://defaria.com> Making music should not be left to the professionals. - Michelle Shocked -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |