John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
Now I understand what each statement does, but can't figure out how it works! The first regex will find the first (") char and turn it into a pair of single quotes. The /s modifier is superfluous.# convert double-quotes to single-quotes if( $$quote && $text =~ s/"/''/s ){ $$quote = 0; } while ($text =~ s/"([^"]*)"/``$1''/sg) {}; $$quote = 1 if $text =~ s/"/``/s;
The second will find pairs of double quotes and replace the first with backticks and the second with two singles.
Then any remaining ("), if there were an odd number (even to begin with since the first was already taken) that last one is converted to backticks.
So... I'm reading that
would convert the first one to close quotes, then pairs with open/close, then the last to open.stuff "passage one" more stuff "passage two" stuff
Isn't that backwards?stuff ''passage one`` more stuff ''passage two`` stuff
—John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: logic for smart quotes - what does this code mean?
by Gorilla (Sexton) on Jan 17, 2003 at 07:11 UTC | |
|
Re: logic for smart quotes - what does this code mean?
by chromatic (Archbishop) on Jan 17, 2003 at 06:26 UTC | |
|
Re: logic for smart quotes - what does this code mean?
by jryan (Vicar) on Jan 17, 2003 at 08:19 UTC | |
by John M. Dlugosz (Monsignor) on Jan 17, 2003 at 16:22 UTC |