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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.