Differences in how to handle strings between Java and Perl

Java and Perl strings

Strings in Java

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";

String in Perl

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)

String concatenation in Java and Perl.

String concatenation in Java

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.

String comparison in Perl

Use the "." Symbol when concatenating strings in Perl. Example 7 my $ str5 = "perl1". "Perl2"; ⇒ Variable $ str5 is "perl1 perl2" Contains the character string.

Compare strings in Java and Perl.

String comparison in Java

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.

String comparison in Perl

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

The difference between Java and Perl.

Declaration and assignment

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.

String concatenation

The "+" symbol is used for string concatenation, which is often used in Java. The "." Symbol is used for string concatenation in Perl.

String comparison

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

Differences in how to handle strings between Java and Perl
How to concatenate strings in java
How to convert A to a and a to A using AND and OR in Java
How to handle TSV files and CSV files in Ruby
Differences between Java, C # and JavaScript (how to determine the degree of obesity)
Differences between "beginner" Java and Kotlin
Difference between Java and JavaScript (how to find the average)
How to learn JAVA in 7 days
[Rails] Differences between redirect_to and render methods and how to output render methods
What happened in "Java 8 to Java 11" and how to build an environment
How to call and use API in Java (Spring Boot)
Let's sort out the differences between Java substring and C # Substring, and how to port them.
How to use classes in Java?
How to name variables in Java
How to develop and register a Sota app in Java
Differences between Java and .NET Framework
How to dynamically switch between FIN and RST in Netty
AtCoder ARC 081 C hash to solve in Ruby, Perl and Java
How to encrypt and decrypt with RSA public key in Java
How to implement Kalman filter in Java
Difference between final and Immutable in Java
[java] Summary of how to handle char
[Java] Differences between instance variables and class variables
[Java] How to output and write files!
How to embed Janus Graph in Java
How to get the date in java
Differences between Ruby strings and symbols [Beginner]
How to switch between multiple Java versions
Java to C and C to Java in Android Studio
Difference between int and Integer in Java
A note on the differences between interfaces and abstract classes in Java
Sorting AtCoder ABC 111 C hashes to solve in Ruby, Perl and Java
How to create your own annotation in Java and get the value
[Java] How to use FileReader class and BufferedReader class
[Understanding] Differences between hashes and arrays in Ruby
Differences in writing Java, C # and Javascript classes
How to get Class from Element in Java
How to hide null fields in response in Java
How to handle optional in Protocol Buffers (proto3)
Distinguish between positive and negative numbers in Java
How to solve an Expression Problem in Java
How to write Java String # getBytes in Kotlin?
Ruby How to convert between uppercase and lowercase
How to access Java Private methods and fields
[Java] How to use Calendar class and Date class
How to ZIP a JAVA CSV file and manage it in a Byte array
Organize your own differences in writing comfort between Java lambda expressions and Kotlin lambda expressions.
How to concatenate strings
How to create a Java environment in just 3 seconds
[Java] How to omit the private constructor in Lombok
[Java] Types of comments and how to write them
How to input / output IBM mainframe files in Java?
Differences between Ruby syntax error statements in Ruby and binary
[Java] Convert character strings to uppercase / lowercase (AOJ⑨-swap uppercase and lowercase)
Java memory management and how to read GC Viewer
[Java] Difference between static final and final in member variables
How to create a data URI (base64) in Java
Java classes and instances to understand in the figure
How to generate / verify ID token in Java Memo
Differences between Fetch Type LAZY and EAGER in Hibernate
How to convert a file to a byte array in Java