Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: When modules install in perl5

by cristofayre (Sexton)
on Sep 25, 2017 at 12:33 UTC ( [id://1200042]=note: print w/replies, xml ) Need Help??


in reply to When modules install in perl5

Just wondering.

Since the files to be changed are preset to "644", this would imply they are readable, but not writable or executable ... so in essence, they cannot be modified by an external script, which is where the violation is coming in.

Maybe the "umask" command set to "000" would temporarily set all the files to "777", and then chmod can change them back to "755" or "705"

Replies are listed 'Best First'.
Re^2: When modules install in perl5
by 1nickt (Canon) on Sep 25, 2017 at 12:48 UTC

    You should consider getting a cloud VM instead of a shared hosting account. You are only seeing the tip of the iceberg as far as the problems you will encounter. You won't be able to install any Perl modules that require compilation, or C libraries that Perl modules need; you won't be able to use a modern version of Perl as some modules require; you can't get on the command line to do normal tasks like changing file permissions (with or without a Perl script to do it), and are forced to try to hack CGI scripts for such work; etc., etc.

    For $10 a month or less you can have your own server with full root access. The time it will take you to learn simple server administration will be less than the time you will spend faffing around in "support" chatrooms with your current host's know-nothing CSRs and do-nothing sysadmins. And you'll be able to set up your working environment as well as your web server just how you like it.

    Personally I use Linode but have heard good things about Digital Ocean as well. Hope this helps!


    The way forward always starts with a minimal test.

      I've used Scaleway without any issues. Starting at 3 euro a month you can have a Dual Core x86 VPS, or 4 dedicated arm core system

Re^2: When modules install in perl5
by cristofayre (Sexton) on Sep 26, 2017 at 16:59 UTC

    For anyone who's curious, the REAL problem was that the file had been uploaded as DOS (CRLF) rather than UNIX (LF only) "Filezilla" auto corrects on upload - but not so cPanel "FileManager"

    Now I got to write a script to check 200+ files on my Windows7 / Strawbery PERL local machine. I will use File::Find::Rule to reiterate through all the folders and sub domains, and open the first line of each file. If it's a CRLF, THEN I will open the file. make the change, and save it out again. Problem at present is getting grep to find the linefeed. Tried escaping and /\x0A\x0D/, but won't play ball!

    #!/usr/bin/perl print "content-type: text/html\n\n"; use CGI::Carp qw( fatalsToBrowser ); use File::Find::Rule; $string="\x0D\x0A"; #my @files = File::Find::Rule->file()->name('*.pl')->in('/home/cristof +a/public_html/'); # set ->in('.') to start from current directory my @files=('D:/home/cristofa/public_html/cgi-bin/dummy/testme.pl'); for ($x=0; $x<@files; $x++){ open THEFILE, "<$files[$x]"; $first_line = <THEFILE>; print $first_line; close THEFILE; if (grep(/$string$/,$first_line)){ print File "$files[$x] is incorrect<br>"; # &correct_file; } } sub correct_file{ open (FILE, "<$files[$x]); while(<FILE>){ $tmp.=$_; } $tmp=~s/[\n\r][\n\r]/\n/g; open (FILE, ">$files[$x]); print FILE $tmp; close(FILE); $tmp=''; } print "All done";
    It is only checking the single test file at this stage, which should print "File XYZ is incorrect" if its working

      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:

      • Use strict and warnings! For example it would have given you a hint that you have a typo in the line print File "$files[$x] is incorrect<br>"; - in fact this is probably one of the issues that is making you think the regex isn't working, when it actually is.
      • You need to check the return value of open for errors, and I'd strongly recommend to use lexical filehandles and the 3-argument form, as in open my $fh, '<:raw', $files[$x] or die "$files[$x]: $!";
      • You should open your files with the :raw layer as I showed above, or binmode them after opening (as the AM post points out), because otherwise, under Windows, your files will be opened with the :crlf layer by default (see PerlIO), another reason your test code might not be working.
      • You've also got a typo in the two open (FILE, "<$files[$x]); lines (again, Use strict and warnings).
      • When reading the entire file into memory, you don't need to read it in a loop, there is a trick to slurp the entire file into memory at once: my $tmp = do { local $/; <$fh> };

      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; } }
      make sure to binmode the files, and use \x0D\x0A instead of \r\n to play it extra safe

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1200042]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found