Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Timeline for XOR two strings

Current License: CC BY-SA 4.0

11 events
when toggle format what by license comment
Jul 19, 2020 at 9:14 comment added Dom Hastings @msh210 It seems to do what's expected in some basic tests without the -Mfeature=bitwise, but there's probably an edge case I'm not aware of... Try it online!
Jul 19, 2020 at 7:43 comment added msh210 @Abigail The challenge specifies input is in the range 0-255. So I think you have to account for newlines in the strings. Maybe do it as a subroutine instead of a standalone script (is that still legal here?), something like pop^.pop?
Jul 19, 2020 at 7:39 comment added msh210 @DomHastings I think ^ instead of ^. and skipping -M won't work if the strings match [0-9]+ (this is from memory; I haven't checked).
Jul 17, 2020 at 18:20 comment added Abigail When testing, I was running the program as perl -M5.032 -nl program.pl < input. This turns on strict, which prohibits an undeclared $x (or any other single letter variable). $; however is always a package variable.
Jul 17, 2020 at 16:09 comment added Dominic van Essen That's very cunning! But in the case of the particular answer above (where the $ isn't the last character), I take it that using $; instead of any other more-easy-for-me-to-understand variable name is just down to taste or habit?
Jul 17, 2020 at 15:04 comment added Dom Hastings @DominicvanEssen It has special uses (although I've not used it as intended: perldoc.perl.org/perlvar.html#%24%3b) but it's really useful to use if your script uses -n/-p as you can use $ alone, because -n wraps your code in while (<STDIN>) {...;} so you can use the implicit ;. I'm using a similar trick in this answer codegolf.stackexchange.com/a/205760/9365 using ; as the delimiter for s/// and relying on the implicit existence. @; and %; would work too!
Jul 17, 2020 at 13:27 comment added Dominic van Essen Q from someone less-experienced in Perl: do you use $; as a variable name for a clever reason, or is it just playful obfuscation?
Jul 17, 2020 at 12:39 comment added Dom Hastings That's very true, it does! Without the -Mfeature=bitwise though, you can avoid the . in ^. for -1!
Jul 17, 2020 at 11:30 comment added Abigail @DomHastings Yeah, but that relies on having the last line of STDIN to not be terminated with a newline, which is kind of icky (and hard to spot when looking at test input). BTW, it's not -Mbitwise, but -Mfeature=bitwise.
Jul 17, 2020 at 11:10 comment added Dom Hastings I didn't even know about -Mbitwise, but I think you can drop it (and the .). For single inputs (which is fine IMO), your intended idea should work too: Try it online!
Jul 17, 2020 at 9:58 history answered Abigail CC BY-SA 4.0

AltStyle によって変換されたページ (->オリジナル) /