$rowfetch =~ s/['-]//g; #All chars inside the [ ] will be filtered out. $rowfetch =~ m/(\w+), ?(.)/; printf $fh lc($2.$1);
I got help building this regular expression yesterday, but I don’t fully understand it.
It takes a name like Parisi, Kenneth and prints out kparisi
Knowns:
s/ = substitute
m/ = match
I tried searching for the rest but couldn’t find anything that really helped explain it.
I also didn’t understand how the =~ is supposed to evaluate to either true or false, yet in this situation, it is modifying the string.
I keep one of these cheat sheets pinned on my cube wall for just such occasions. Google for
regular expression cheat sheetto find others.To add to what you already know:
The magic is in the grouping — the match expression uses the groups and puts them into variables $1 and $2. In this case $1 matches the word before the comma and $2 matches the first character following the whitespace after the comma.