Quote:
Originally Posted by liuqiong7618
hello:
I want to open the document,find the line including "disable = yes",
then replace the word "yes" to "no"
the purl language is new to me,hope to get your help:
The programming as following, but it failed:
#open the securetty
if (!open(FILE,"/etc/securetty"))
{
print "The file can't be found";
exit;
}
while ($line = <>)
{
chomp($line);
printf $line;
# fine the line that includes "disable = yes"
line1 ='"$line" | grep "disable = yes"';
if [-n "$line1" ]
then
# replace the word "yes" to "no"
sed 's/yes/no/';
else
then print "The string cannot be found";
}
|
Use CODE tags (go to advanced menu and look for '#' button).
The language is called Perl.
Now, based on what Perl documentation did you write
Code:
line1 ='"$line" | grep "disable = yes"';
...
if [-n "$line1" ]
...
sed 's/yes/no/';
?
I suggest to first read
perldoc perlop
perldoc perlfunc
perldoc perlretut
.
You can also find Perl documentation online:
http://perldoc.perl.org/ .
You are trying to write Perl code not understanding very basic things about Perl, like regular expressions, for example. You do no need to call 'sed' or 'grep' from Perl programs.