Basically, the character string is enclosed in "" "(double quotation marks). Example "java"
When handling as a variable, declare the String type and then assign it. Example String str = "java1";
With "'" (single quotes) or "" "(double quotes) The bundle is a character string. Example 1'perl1' Example 2 "perl2"
When treating it as a variable, it can be assigned to the variable as it is without being aware of the concept of type. Example 3 my $ str1 ='perl1'; Example 4 my $ str2 ='perl2';
Also, in Perl, a character string is added to a variable using a description method called here document. It is also possible to substitute. Example 5 my $ str3 <<'EOD' abc defg hijkl EOD ("Abcdefghijkl" is stored in a variable)
When concatenating strings in Java, the "+" operator and "concat" method, You can use the StringBuffer class or the StringBuilder class. Example 6 String str4 = "java1" + "java2"; ⇒ Variable str4 is "java1 java2" Contains the character string.
Use the "." Symbol when concatenating strings in Perl. Example 7 my $ str5 = "perl1". "Perl2"; ⇒ Variable $ str5 is "perl1 perl2" Contains the character string.
When comparing strings in Java, use the "equals" method. Example 8 "java1" .equals ("java2"); ⇒ The result is false
When comparing using the "==" symbol in Java, a compile error occurs.
When comparing strings in Perl, use strings such as "eq" and "ne" Use operators for comparison. Example 9 "perl1" ne "perl2"; ⇒ The result is true
Java has to type variables and use double quotes, whereas Java has to use double quotes.
Perl doesn't require you to specify the type of the variable, it doesn't have to be double quotes. Above all, you can assign a character string to Perl using a description method called here document. There is no here document in Java.
The "+" symbol is used for string concatenation, which is often used in Java. The "." Symbol is used for string concatenation in Perl.
Java uses the "equals" method. Perl uses operators for string comparisons such as "eq" and "ne".
Finally Since I was involved in web applications in Java development, Perl comparison operators It's familiar, but the fact that you can use the "." Symbol to concatenate characters and substitute them in here-documents I'm not used to it.
Recommended Posts