neidu2, (edited )

using regex to find the absolute value of a number:
$number =~ s/-//;

using regex to check if a number is odd:
print “odd!\n” if (($number / 2) =~ /./)

…and generally abusing regex for weird stuff it wasn’t intended for, because the regex engine is surprisingly efficient.

🌼 Just PERLy Things! 🌼

  • All
  • Subscribed
  • Moderated
  • Favorites
  • asklemmy@lemmy.world
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #