Been banging away at this now for HOURS, but again I am too stupid and must yield to the superior intellects..
I want to take a string and flip chars 1&2, then 2&3, etc. I got it where I could flip 1&2, then 3&4, but that isn't quite it. I keep running into this one problem and I can't figure out why. Here is my code (sad but true):
for (@words) {
while(/(.)/g) {
$flip = $_;
$flip =~ s/$1\./\.$1/ge; # flip match + next char
print $flip;
}
}
I am getting various errors, but nothing helpful in spite of using "perl -w". I am using the $flip var so I don't change the value of $_ ( I want to do some more stuff later on with it, and I want to stay the same throughout.. probably a better way to do that too, but we only know what we know). Can I not call $1 in my search and replace?? It never seems to work right. It does seem to work if I copy $1 to another var and then use that in my regexp.. I really need to sit down with my "Mastering Regular Expressions" book and quit pestering you guys. =)
So, the output of say "jigglewort" is:
ijgglewort
jgiglewort
jigglewort
jiglgewort
...
The current error message is:
syntax error at flipchar.pl line 19, near "\."
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.