Sorry to trouble you with what may be a trivial prob, but I'd be grateful if any monk wd cast a critical eye over the following.
It's a little utility for when I upload my scripts from my win98 machine to my Linux web space. Whilst I'd value comments on the structure of the script (and am even prepared to be told there's already a module to do this), what I'm stumped on is how to get
chmod to work.
The simple statement of the problem is, it doesn't work. The file permissions stay the same. And even when I replace
$_ with the name of a file in the dir it doesn't work. I know next to nothing about system administration, and it may well be some webspace / OS specific problem - I'd be grateful for any thoughts on that. But if it's in the code, please hit me with a haddock.
Yer tiz:
print $q->header;
print $q->start_html;
while (<*.pl>) {
next if $_ eq 'replace.pl';
print "<B>$_</B><BR>";
$old = $_;
open GET, $old;
print "opening $old<BR>";
$new = substr($old,0,(length $old) -2) . 'bak';
open PUT, ">$new";
print "opening $new<BR>";
print PUT $_ while <GET>;
print "writing $old into $new<BR>";
close GET;
close PUT;
print "closing $old and $new<BR>";
open GET, "$new";
open PUT, ">$old";
print "reopening $old and $new<BR>";
while (<GET>) {
$_ =~ s/c:\\perl\\bin\\perl/\/usr\/bin\/perl/;
$_ =~ s/\("DBI:mysql:database=foo"\)/("DBI:mysql:database=foo"
+,"bar","baz")/;
print PUT $_;
}
print "altering lines in $new and writing to $old<BR>";
close GET;
close PUT;
print "closing $old and $new<BR>";
$cnt = chmod 0755, $old;
if ($cnt) {
print "changing file permissions for $old<BR>";
}
else {
print "cannot change file perms for $old<BR>";
}
print "<BR>";
}
print "DONE";
print $q->end_html;
§
George Sherston
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.