I made a program that extracts quotes while retaining special inner quotes (in this case an 'x' followed by an apostrophe). The original program is far more complicated than this, but I wanted to make it simple to troubleshoot.
I want to take these two perl commands and have the first command's results be piped into the second commands input but while only running perl once:
Input: ['Say, x'Hix'']
echo "['Say, x'Hix'']" | perl -lne 'push @a,/\[\N{U+0027}(.*?)(?<!x)\N{U+0027}/g; END{print "@a"};'
Output: Say, x'Hix'
Taking the output of the first command:
echo "Say, x'Hix'" | perl -pe 's/x\N{U+0027}/\N{U+0027}/g; END{print "@a"};'
Result (proper): Say, 'Hi'
I realise that I could easily just run perl twice and pipe them into eachother, but running perl twice seems inefficient; especially given that this command is ran thousands of times:
echo "['Say, x'Hix'']" | perl -lne 'push @a,/\[\N{U+0027}(.*?)(?<!x)\N{U+0027}/g; END{print "@a"};' | perl -pe 's/x\N{U+0027}/\N{U+0027}/g; END{print "@a"};'
I've tried combining both commands in the code below, but it doesn't seem to be taking the output of the first command as input for the second:
echo "['Say, x'Hix'']" | perl -lne 'push @a,/\[\N{U+0027}(.*?)(?<!x)\N{U+0027}/g; END{print "@a"};' -pe 's/x\N{U+0027}/\N{U+0027}/g; END{print "@a"};'
Result (not what I want):
['Say, 'Hi'']
Say, x'Hix'
Say, x'Hix'
Any ideas?