in reply to Re^2: When modules install in perl5
in thread When modules install in perl5
Since this is a different topic than the one in the root node, if you have more issues/questions, I recommend starting a new thread. There are a few issues with the code, and potential improvements:
Personally I find the regex s/[\n\r][\n\r]/\n/g a little too flexible: If the file for some reason contains mixed CR/LF line endings, this regex might muck them up even more. Plus, if there are mixed endings, just checking the first line isn't enough. Here's how I might have written a script like this, even though there is no need to reinvent this wheel - for example, the fromdos tool from the Tofrodos package could already be installed on your system.
#!/usr/bin/env perl use warnings; use strict; use Getopt::Std 'getopts'; our $VERSION = '0.01'; $Getopt::Std::STANDARD_HELP_VERSION = 1; getopts('qi', \my %opts) or die "Usage: $0 [-q] [-i] FILE(s)\n"; if ( !@ARGV || (!$opts{i} && $opts{q}) ) { warn "No actions to perform\n"; exit 1 } for my $file (@ARGV) { open my $ifh, '<:raw', $file or die "$file: $!"; my $data = do { local $/; <$ifh> }; close $ifh; if (not $opts{q}) { my $cr = () = $data=~/\x0D(?!\x0A)/g; my $lf = () = $data=~/(?<!\x0D)\x0A/g; my $crlf = () = $data=~/\x0D\x0A/g; print "$file: ", ( join(', ', $cr?"$cr CR":(), $lf?"$lf LF":() +, $crlf?"$crlf CRLF":() ) || 'no CR or LF' ), "\n"; } if ($opts{i}) { $data =~ s/\x0D\x0A?|\x0A/\n/g; open my $ofh, '>:raw', $file or die "$file: $!"; print $ofh $data; close $ofh; } }
|
|---|