Using Raku (formerly known as Perl_6)
raku -pe 's{(.*)}=qq{\$wgSpecialPageLockdown[\x27$0\x27] = array(\x27sysop\x27);};'
OR
raku -ne 'put .map: qq{\$wgSpecialPageLockdown[\x27} ~ * ~ qq{\x27] = array(\x27sysop\x27);};'
Sample Input:
A1
B2
C3
D4
E5
Sample Output:
$wgSpecialPageLockdown['A1'] = array('sysop');
$wgSpecialPageLockdown['B2'] = array('sysop');
$wgSpecialPageLockdown['C3'] = array('sysop');
$wgSpecialPageLockdown['D4'] = array('sysop');
$wgSpecialPageLockdown['E5'] = array('sysop');
Above are answers coded in Raku, a member of the Perl-family of programming languages. Each answer uses a command line flag(s): the first answer uses the -pe
autoprinting linewise flag(s), while the second answer uses the -ne
non autoprinting linewise flag(s), with a leading put
command to print output. Both answers take advantage of the fact that Raku allows user-defined delimiters: both answers use {…}
curly brace delimiters.
In the first answer above, the familiar s///
idiom is used, with a new form provided in Raku: s{…}={…}
(or s[…]=[…]
, or s「…」=「…」
, etc.). This new form allows the programmer to determine quotation/interpolation via Raku's "Q-Language" (i.e. quotation construct notation). The qq
method instructs Raku to interpolate variables and backslashed characters. Each line is captured in the left half of the s{…}=qq{…}
operator using (.*)
and stored in the $0
variable. Output is then wrapped (prepended/appended) with additional text in the right half of the s{…}=qq{…}
operator, and autoprinted.
- Raku uses 4 primary sigils:
$
, @
, %
, and &
. Inside the qq
operator these literal characters need to be backslash escaped, otherwise Raku will try
to interpolate them. The exception is the @
array sigil: as a literal character @
doesn't
need to be escaped (convenient for email addresses), but when printing an actual @array1
variable,
you add empty indexing square brackets at the end to force
interpolation, like so: @array1[]
.
The second answer above is even simpler. Basically each line is read, .map
-ped into, and wrapped with text before ("prepend") and after ("append"). In Raku, string concatenation is accomplished with ~
tilde, and mapped input is represented by a *
"whatever star". The *
"whatever star" is used in lieu of using $_
topic variable inside a {…}
curly_brace-denoted code block.
As noted in other answers, \x27
the hex representation of a single-quote character can be used in Raku, either as above, or as \x[27]
. However if you tire of remembering hex codes, just spell out the character you want to insert like so: \c[APOSTROPHE]
(or \c[QUOTATION]
, or whatever your difficult-to-insert character happens to be). Here's what those answers look like:
raku -pe 's{(.*)}=qq{\$wgSpecialPageLockdown[\c[APOSTROPHE]$0\c[APOSTROPHE]] = array(\c[APOSTROPHE]sysop\c[APOSTROPHE]);};'
OR
raku -ne 'put .map: qq{\$wgSpecialPageLockdown[\c[APOSTROPHE]} ~ * ~ qq{\c[APOSTROPHE]] = array(\c[APOSTROPHE]sysop\c[APOSTROPHE]);};'
Addendum: Did I mention doublequotes were sytactic sugar for qq
quoting? So, while the above answers work nicely for our Windows friends, the doublequotes below also work on appropriate (Linux, Mac) systems:
raku -pe 's[(.*)] = "\$wgSpecialPageLockdown[\x27$0\x27] = array(\x27sysop\x27);";'
OR
raku -ne 'put .map: "\$wgSpecialPageLockdown[\x27" ~ * ~ "\x27] = array(\x27sysop\x27);";'
https://docs.raku.org/language/quoting
https://raku.org