6. ChatGPT & Other AIs

https://openai.com provides ChatGPT, a general-purpose chatbot that uses artificial intelligence to generate text after a user submits a question. Of course, that question can be on Perl! I've to say many answers are excellent. However, you've to be familiar with Perl to assess whether or not ChatGPT produces accurate information. In case of Perl, many answers on Perl questions are possible, so you've to decide if ChatGPT's answer can be better. An example:


ChatGPT: You can remove leading zeros from a string in Perl using regular expressions. Here's an example:

my $string = "00123";
$string =~ s/^0+//; # Removes leading zeros
print($string); # Output: "123"

In this code, the regular expression ^0+ matches one or more leading zeros at the beginning of the string 
and replaces them with nothing, effectively removing them.  
Of course a great answer. But what about this alternative?

print(int("00123")); # Output: "123"
You want a string as in the regex solution? You can use int() to remove the leading zeros and then cast it back to a string. This is as simple as interpolating or concatenating:

my $string = "00123";
my $result = "" . int($string); # Cast back to string
print($result); # Output: "123"

Tip
One advantageous option is to provide the output from, for example, ChatGPT to other AI tools like Perplexity or Le Chat. Often, they produce concurrent answers, which is an excellent way to learn from them.