sub dos2unix { # Takes array containing file-paths as argument my (@files2Convert) = @_; foreach my $file (@files2Convert) { if (-e $file) { print "Converting $file...\n"; # load file contents into memory for conversion open(FILE, "$file") or die "Can't open $file: $!"; my @lines = ; close(FILE) or die "Can't close $file: $!"; # here's where the actual conversion takes place foreach my $i ( 0..$#lines ) { $lines[$i] =~ s/\015\012/\012/g; } # make backup copy of file in case this module dies halfway through # the write to the new file. (We only have this file info in memory at that point.) rename("$file","${file}.bak") or die "Couldn't make backup copy of $file: $!"; # write new data open(FILE,">$file") or die "Can't open $file: $!"; print FILE @lines; close(FILE) or die "Can't close $file: $!"; # remove backup if all is successful unlink "${file}.bak" or warn "Couldn't remove backup of $file: $!"; } } } #### $lines[$i] =~ s/\015\012/\012/g; $lines[$i] =~ s/\n/\012/g; $lines[$i] =~ s/\x0D\x0A/\012/g; $lines[$i] =~ s/\015\012/\x0A/g; $lines[$i] =~ s/\n/\x0A/g; $lines[$i] =~ s/\x0D\x0A/\x0A/g; #### use Socket qw(:DEFAULT :crlf); local ($/) = LF; $lines[$i] =~ s/$CRLF/$LF/g; #### $lines[$i] =~ s/\012//g;