#!/usr/bin/perl -w
$import_file="file-list-to-import.txt";open(DAT, $import_file) ¦¦ die("Could not open file: $import_file");
@data=split('s.',<DAT>); # Splits each newline
close(DAT);
print "Content-type: text/html\n\n"; # Default header
print "<html><title>Perl CHMOD</title><body>";
foreach $item (@data)
{
chmod (0666, $item);
print "File changed: $item";
print "<br>";
$count++
}
print "Total files changed: $count\n";
print "</body></html>";
The above code prints the following:
File changed: /home/rp
File changed: public_html/myrp
File changed: config.php
Total files changed: 3
Here is the imported file:
/home/rps/public_html/myrps/config.php
/home/rps/public_html/myrps/config_override.php
/home/rps/public_html/myrps/config.php the above regexp means to split on the letter 's' followed by any single character. Which is what your output shows. You probably want to do this:
#!/usr/bin/perl -w
$import_file="file-list-to-import.txt";open(DAT, $import_file) or die "Could not open file: $import_file";
@data=<DAT>;
close(DAT);
chomp(@data);print "Content-type: text/html\n\n"; # Default header
print "<html><title>Perl CHMOD</title><body>";foreach $item (@data)
{
if (chmod (0666, $item)) {
print "File changed: $item<br>\n";
$count++
}
else {
print "File not changed: $item<br>\n";
}
}
print "Total files changed: $count\n";
print "</body></html>";
I'm having another problem with the "or die" command.
My output is a blank page for this:
#!/usr/bin/perl -w
$import_file="file-list-to-import.txt";open(DAT, $import_file) ¦¦ die("Could not open file: $import_file");
@data=<DAT>;
close(DAT);
print "Content-type: text/html\n\n"; # Default header
print "<html>
<head>
<title>Perl CHMOD</title>
</head>
<body>\n";
foreach $item (@data)
{
$temp = 0;
chmod (0644, $item) or die $temp = 1;
if ($temp == 0 ) {
print "File changed: $item\n<br />";
}
elsif ($temp == 1) {
print "Could not change file: $item\n<br />";
$temp = 0;
}
# chmod (0755, $item) ¦¦ print("Could not change file: $item\n<br />");
# print "File changed: $item";
# print "<br />";
$tot_count++
}
print "Total files changed: $tot_count\n";
print "
</body>
</html>";
I want to have a message displayed if the file was changed ok, and then another displayed if it was not changed ok. My idea was on the "or die" command, I change the value of a variable, then use an if statement below to print the correct statement.
[edited by: vygbuyhnmj at 6:51 pm (utc) on June 15, 2006]
#!/usr/bin/perl -w
$import_file="file-list-to-import.txt";open(DAT, $import_file) ¦¦ die("Could not open file: $import_file");
@data=<DAT>;
close(DAT);
print "Content-type: text/html\n\n"; # Default header
print "<html>
<head>
<title>Perl CHMOD</title>
</head>
<body>\n";
foreach $item (@data)
{
$temp = 0;
chmod (0644, $item) or $temp = 1;
if ($temp == 0 ) {
print "File changed: $item\n<br />";
$tot_count++
}
if ($temp == 1) {
print "Could not change file: $item\n<br />";
$temp = 0;
}
# chmod (0755, $item) ¦¦ print("Could not change file: $item\n<br />");
# print "File changed: $item";
# print "<br />";
}
print "Total files changed: $tot_count\n";
print "
</body>
</html>";