in reply to Re: Script won't run
in thread Script wont run
print out the entire line but I want only the name and password to show up it showsprint "Enter the plain text password for $name, ", "password is currently '$password'\n";
I tried the following to just get the name and password only but it only returns 0 and 1 lolEnter the plain text password for "Q9" Type="Container" Expanded="True +" Descr="" Icon="mRemote" Panel="General" Username="" Domain="", pass +word is currently '""'
Also can you please tell me what the following means from your code.my @names = grep /\bName=(.*?)/ , @array; my @password = grep /\bPassword=(.*?)/ , @array; my $newline = $line; # Make a copy print "name is $names[0] and password is $password[0]\n";
?:\s+|$) /mgx also Q$password\E}
|
|---|
| Replies are listed 'Best First'. | |||
|---|---|---|---|
|
Re^3: Script won't run
by AnomalousMonk (Archbishop) on Nov 22, 2015 at 23:25 UTC | |||
... can you please tell me what the following means from your code.
This should be (?:\s+|$) (a non-capturing grouping), To explain these: Remember that \Q...\E metaquotes any non-\w character literal or interpolated character. See the \Q \L \l \U \u \E interpolation control escape sequences in Quote and Quote-like Operators in perlop; see also quotemeta. Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] | ||
by cbtshare (Monk) on Nov 23, 2015 at 03:13 UTC | |||
Thank you very much , this helped alot. I am still having a bit of trouble with the script,it will not update the file, unless $line = $newline; is inside the while loop
| [reply] [d/l] | ||
by Athanasius (Archbishop) on Nov 23, 2015 at 03:37 UTC | |||
As I explained above, you can’t put the assignment $line = $newline; inside the while loop, because updating $line resets the /g match position to the beginning of the string, creating an infinite loop. I tested my code before posting, and when the assignment $line = $newline; occurs after (i.e., outside) the inner loop, the tied file is updated correctly. I suspect your current problem is that the regex match is failing. In light of your subsequent post, it appears your data file never contains a string matching / Name=(.*?) \s+ Password=(.*?) (?:\s+|$) /mx. You will need to adapt the while loop regex to the actual format of the data in the input file. For example (untested):
or just:
Update (25th November, 2015): Changed / < \s* Name= to / < Node .*? Name= in each regex. Hope that helps,
| [reply] [d/l] [select] | ||
by cbtshare (Monk) on Nov 23, 2015 at 19:13 UTC | |||
wrapping the old password with \Q\E means that it will remain unchanged evidenced by : The sentence remain unchanged, so why do \q\e instead of just doing s{$password}{$newpass} The script I ended working with is , do you have any recommendations or critque, and also can you suggest how I could get it to update immediately to the file instead of waiting till the loop ends?
| [reply] [d/l] [select] | ||
by Athanasius (Archbishop) on Nov 25, 2015 at 08:15 UTC | |||
Hello again cbtshare, wrapping the old password with \Q\E means that it will remain unchanged ..., so why do \q\e instead of just doing s{$password}{$newpass} The purpose of adding \Q to a regex is to prevent any “special” regex characters from having their special meanings. For example, if the data contains:
then without a \Q the $ will be interpreted to mean match the end of a line, which will cause the match to fail (unless abcde actually happens to come immediately before the end of a line, followed immediately by " at the beginning of the next line). But when preceded by a \Q, special characters like $, ., +, and * lose their special regex meanings and are treated as literal characters. That’s why, if there’s any possibility that a password may contain a character which the Perl regex engine considers to be “special,” it’s good practice to add \Q ... \E around the variable containing that password. can you suggest how I could get it to update immediately to the file instead of waiting till the loop ends? That depends on which loop you have in mind. As I explained above, the file can’t be updated within the inner (while) loop. However, the file is already being updated between each iteration of the outer (foreach) loop. You can see this by adding another <> as follows:
Assuming a file named “REMOTEopen.xml” is present in the current directory and contains data like this:
you can check the contents of the data file each time Press <Enter> to continue... is printed to the screen, and you should see that the file has indeed been updated as expected. Hope that helps,
| [reply] [d/l] [select] | ||
by cbtshare (Monk) on Nov 23, 2015 at 17:52 UTC | |||
| [reply] [d/l] | ||