Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Active State Perl with Unix-line endings -- Help

Thread Tools

Active State Perl with Unix-line endings -- Help

Brian & Colleen
Posts: n/a
I'm using Active State Perl on a WinXP machine. I also run Cygwin and I
decided I wanted a utility to clean my .bash_history file to remove some
commands and duplicate lines.

The line endings are driving me nuts because I think Perl assumes it's on a
Win Platform but bash is writing Unix-style line endings. I keep ending up
with spurious ^M's in my .bash_history. I'm trying to force things with $/
and $\ but it isn't working. As you can tell from the code, I'm new to Perl
so it's probably something really simple.
use strict;

$/ = "\012"; # force use of Unix-style line endings as created
$\ = "\012"; # bash. Strip them on input and restore on output.

my $delstr = qr /exit|cd|ls|rm|cat|pwd|which/ ;
my $oldline = "zzzzzzz";
my $line = "";

while ($line=<INFILE>){
chomp $line;
if (($line !~ /$delstr/) && ($line ne $oldline)){
print OUTFILE "$line";
$oldline = $line;
close INFILE;
close OUTFILE;

if (rename ".bash_history2",".bash_history") {
print "Done.";



Reply With Quote
Brian & Colleen
Posts: n/a
Good point both Tim and Bob made about using Unix tools to solve Unix
problems. I updated my Cygwin to include Perl and that seems to take care of
the confusion over line endings. What I thought should be a good little
"learning" project turned out to be more educational than I bargained for.

Thanks for the suggestions.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with regular expression for matching the url endings erenay Java 6 06-06-2006 08:16 PM
Detecting line endings Fuzzyman Python 18 02-08-2006 12:10 PM
UTF16, BOM, and Windows Line endings Fuzzyman Python 4 02-07-2006 09:23 AM
.bin + .cue file endings? Lisa Taylor Computer Support 6 08-26-2004 07:46 AM
Compiling Perl to exe with Active State Perl Maciej Kozinski Perl 0 11-28-2003 11:48 AM