Hello All,
I have a perl script to search string in a file and then request input from STDIN and then replace that string with the new input.The script works, but I just cant see to get the search and replace part right, I got an error saying file only open for reading, and now when I try to open it for appending , it just wont run
#!/usr/bin/perl
use strict;
use warnings;
my ($found, $pass, $name, $line, @array, @sarray, @files, @names, @pas
+sword);
my $filename='/home/stain/Downloads/REMOTEopen.xml';
open(XML, "+>> $filename") || die ("Error: $!");
chomp(@array=<XML>);
foreach(@array)
{
@sarray=split(" ", $_);
@names = grep /\bName=/, @sarray;
@password = grep /\bPassword=/, @sarr
+ay;
if (@password)
{
foreach(@names, @password)
{
print XML qq(Enter the plain text pas
+sword for $_, password is currently "$password[0]"\n);
chomp($pass=<>);
print qq(You will now swap $password[
+0] for Password="$pass"\n);
print "continue? y/n\n";
chomp(my $ans=<>);
if ($ans =~/y/im)
{
s/$password[0]/Passwor
+d=$pass/ ;
print XML $_;
}
}
}
}
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.