Skip to main content
added 20 characters in body
Source Link
jubilatious1
  • 3.9k
  • 10
  • 20

Using Raku (formerly known as Perl_6)

raku -e 'put S:g/^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$ /{$1 < 20 ?? "$0 bgcolor=\"red\">\n$1" !! "$0>\n$1"}/ given lines.join("\n");' 

#OR

raku -e 'put S:g[^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$] = $1 < 20 ?? "$0 bgcolor=\"red\">\n$1" !! "$0>\n$1" given lines.join("\n");' 

OR

raku -e 'put S:g/^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$ /{$1 < 20 ?? "$0 style=\"background-color:#ff0000;\">\n$1" !! "$0>\n$1"}/ given lines.join("\n");'

#OR

raku -e 'put S:g[^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$] = $1 < 20 ?? "$0 style=\"background-color:#ff0000;\">\n$1" !! "$0>\n$1" given lines.join("\n");' 

Examples 1 and 2 substitute-in bgcolor="red". Examples 3 and 4 substitute-in style="background-color:#ff0000;", to produce html that works on modern browsers.

Briefly, the examples use use Raku's "big-S" substitution operator, which (according to the docs), "leaves the original string intact and returns the resultant string instead of $/ (the match variable)".

Raku's "big-S" operator is used with Raku's ternary operator in all 4 examples above. Raku's ternary operator is spelled: "'Condition' ?? 'True' !! 'False'".

Examples 1 and 3 use the traditional S/old/new/ format, which in Raku can take a codeblock in the right half. Examples 2 and 4 use the more modern S[old] = "new" or S[old] = [new] substitution operator format, which (as demonstrated) can take ternary operators and/or conditional statements (essentially a codeblock without the curly braces).

https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS
https://docs.raku.org/language/operators#index-entry-operator_ternary
https://raku.org

Using Raku (formerly known as Perl_6)

raku -e 'put S:g/^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$ /{$1 < 20 ?? "$0 bgcolor=\"red\">\n$1" !! "$0>\n$1"}/ given lines.join("\n");' 

#OR

raku -e 'put S:g[^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$] = $1 < 20 ?? "$0 bgcolor=\"red\">\n$1" !! "$0>\n$1" given lines.join("\n");' 

OR

raku -e 'put S:g/^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$ /{$1 < 20 ?? "$0 style=\"background-color:#ff0000;\">\n$1" !! "$0>\n$1"}/ given lines.join("\n");'

#OR

raku -e 'put S:g[^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$] = $1 < 20 ?? "$0 style=\"background-color:#ff0000;\">\n$1" !! "$0>\n$1" given lines.join("\n");' 

Examples 1 and 2 substitute-in bgcolor="red". Examples 3 and 4 substitute-in style="background-color:#ff0000;", to produce html that works on modern browsers.

Briefly, the examples use use Raku's "big-S" substitution operator, which (according to the docs), "leaves the original string intact and returns the resultant string instead of $/ (the match variable)".

Raku's "big-S" operator is used with Raku's ternary operator in all 4 examples above. Raku's ternary operator is spelled: "'Condition' ?? 'True' !! 'False'".

Examples 1 and 3 use the traditional S/old/new/ format, which in Raku can take a codeblock in the right half. Examples 2 and 4 use the more modern S[old] = "new" substitution operator format, which (as demonstrated) can take ternary operators and/or conditional statements (essentially a codeblock without the curly braces).

https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS
https://docs.raku.org/language/operators#index-entry-operator_ternary
https://raku.org

Using Raku (formerly known as Perl_6)

raku -e 'put S:g/^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$ /{$1 < 20 ?? "$0 bgcolor=\"red\">\n$1" !! "$0>\n$1"}/ given lines.join("\n");' 

#OR

raku -e 'put S:g[^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$] = $1 < 20 ?? "$0 bgcolor=\"red\">\n$1" !! "$0>\n$1" given lines.join("\n");' 

OR

raku -e 'put S:g/^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$ /{$1 < 20 ?? "$0 style=\"background-color:#ff0000;\">\n$1" !! "$0>\n$1"}/ given lines.join("\n");'

#OR

raku -e 'put S:g[^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$] = $1 < 20 ?? "$0 style=\"background-color:#ff0000;\">\n$1" !! "$0>\n$1" given lines.join("\n");' 

Examples 1 and 2 substitute-in bgcolor="red". Examples 3 and 4 substitute-in style="background-color:#ff0000;", to produce html that works on modern browsers.

Briefly, the examples use use Raku's "big-S" substitution operator, which (according to the docs), "leaves the original string intact and returns the resultant string instead of $/ (the match variable)".

Raku's "big-S" operator is used with Raku's ternary operator in all 4 examples above. Raku's ternary operator is spelled: "'Condition' ?? 'True' !! 'False'".

Examples 1 and 3 use the traditional S/old/new/ format, which in Raku can take a codeblock in the right half. Examples 2 and 4 use the more modern S[old] = "new" or S[old] = [new] substitution operator format, which (as demonstrated) can take ternary operators and/or conditional statements (essentially a codeblock without the curly braces).

https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS
https://docs.raku.org/language/operators#index-entry-operator_ternary
https://raku.org

Source Link
jubilatious1
  • 3.9k
  • 10
  • 20

Using Raku (formerly known as Perl_6)

raku -e 'put S:g/^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$ /{$1 < 20 ?? "$0 bgcolor=\"red\">\n$1" !! "$0>\n$1"}/ given lines.join("\n");' 

#OR

raku -e 'put S:g[^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$] = $1 < 20 ?? "$0 bgcolor=\"red\">\n$1" !! "$0>\n$1" given lines.join("\n");' 

OR

raku -e 'put S:g/^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$ /{$1 < 20 ?? "$0 style=\"background-color:#ff0000;\">\n$1" !! "$0>\n$1"}/ given lines.join("\n");'

#OR

raku -e 'put S:g[^^ (\< td) \> $$ \n ^^ (<digit>**2) \% $$] = $1 < 20 ?? "$0 style=\"background-color:#ff0000;\">\n$1" !! "$0>\n$1" given lines.join("\n");' 

Examples 1 and 2 substitute-in bgcolor="red". Examples 3 and 4 substitute-in style="background-color:#ff0000;", to produce html that works on modern browsers.

Briefly, the examples use use Raku's "big-S" substitution operator, which (according to the docs), "leaves the original string intact and returns the resultant string instead of $/ (the match variable)".

Raku's "big-S" operator is used with Raku's ternary operator in all 4 examples above. Raku's ternary operator is spelled: "'Condition' ?? 'True' !! 'False'".

Examples 1 and 3 use the traditional S/old/new/ format, which in Raku can take a codeblock in the right half. Examples 2 and 4 use the more modern S[old] = "new" substitution operator format, which (as demonstrated) can take ternary operators and/or conditional statements (essentially a codeblock without the curly braces).

https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS
https://docs.raku.org/language/operators#index-entry-operator_ternary
https://raku.org