What is the longest line I can have?

Recently, I was asked to answer a question about changing a string in perl. I wrote the code and they wanted me to give some lines for testing. I gave them examples like a string with several characters, many characters, invalid characters, etc. But they also asked what is the longest line with which I will test. I was not sure what to say. Hence this question. What is the longest line I can check in Perl code? What does it depend on? Memory by car? Is there any limitation in terms of perl?

+6
source share
2 answers

I was looking if I could find any official documentation on the longest line. I found one at http://perltutorial.org talking about Strings:

Perl defines a string as a sequence of characters. The shortest line does not contain a character or a null line. The longest line can contain unlimited characters, which are limited only by the available memory of your computer.

I do not know if this is enough for you. It would be nice to see something in the FAQ or Perldoc.

By the way, to officially change the line in Perl:

my $rev_string = reverse $string; 

This is in Perl FAQ # 4, which has a bunch of string processing elements. The reverse string question is an old interview question with the interlocutor to find out if anyone knows their secret Perl material. Of course, almost everyone knows that reverse will change the array, but do they know that this will change the string? Noobies will develop some kind of complex algorithm, and the interviewer will have a reason to feel complacent and not to hire this person.

Personally, if I was talking with someone, I asked this question, and someone came up on the spot with an elegant algorithm and showed me how it would work with short, long and unacceptable characters, I would hire them. You can always learn about Perl's new silly tricks, but quick thinking is hard to find.

I have long known the opposite trick when someone asked me the same question in an interview. I looked through it and found it in the FAQ and realized that I did it wrong. I have been using Perl for almost 20 years, and I can't figure out how long I had to change the Perl line.

+6
source

In essence, this depends on the amount of memory available to your program (i.e., Perl). If you have a 32-bit machine, then somewhere under 4 gigabytes. If you have a 64-bit machine, then the limit is probably larger and depends on the available virtual memory. There is no fixed restriction.

+5
source

Source: https://habr.com/ru/post/918855/


All Articles