Where in a pearl weak typification? There are different operators for strings and numbers, so the conversion between them is not implicit .

  • Well, what? No one can answer? - Smit Johnth

3 answers 3

First, remember what built-in data types are in Perl:

Perl has three built-in data types : hashes, arrays of scalars, and associative arrays of scalars.

and also define the terminology:

All data in Perl is a scalar, an array of scalars, or a hash of scalars. There are a number of flavors : a string, a string, or a reference.

And pay attention to the reasons for this automatic conversion.

Scalars are not necessarily one thing or another. There is no place to declare a type of "string", a type "number", a type "reference", or anything else . It is not necessary to take care of the scalars . Perl is a contextually polymorphic language of which it can be strings, numbers, or references (which includes objects).

http://perldoc.perl.org/perldata.html

Once again, make sure that all sorts of conversions occur only with the format, and not with the type:

It’s a different way to make it. It doesn’t change the number stored in the value.

...

It means that it’s not possible to change the number of permissions. In particular, however, it may be time-consuming, repeated operations will not be necessary.

http://perldoc.perl.org/perlnumber.html

Summary

  1. Perl has only three data types: scalars, arrays of scalars and scalar hashes.
  2. A scalar can contain a value in three different forms : a number, a string, and a link.
  3. Since in Perl, there is no place for preliminary declaration of a scalar in the form of a specific type "string", "number" and "link", as it is done for example in C, the compiler cannot know for sure which particular form of scalar it requires a transformation or calling function that returns a scalar:

    $result = get_foobar(); # $result может быть числом, строкой или ссылкой 
  4. If necessary, Perl converts the forms, but not the types themselves.

Thus, the typing in Perl is very specific, consisting of three types, and the conversion itself between their forms, or more precisely between scalar forms, can be either explicit or implicit, depending on the operation applied to them.

  • Great, but can you now give an example of implicit conversion? - Smit Johnth
  • @SmitJohnth perl -E '$a = 3; say "YES" if $a eq "3"; perl -E '$a = 3; say "YES" if $a eq "3"; - edem
  • Another question? eq converts operands to strings. - Smit Johnth
  • @SmitJohnth, yes, it converts scalar shapes, which is what the answer says. PS Rude here just do not advise. - edem
  • one
    @SmitJohnth This is an example of operator overload, not an implicit conversion, although it also occurs there. Implicit type conversion implies conversion of all operands to one type before performing the operation. In Perl, this also happens with formats (because representations in the required format are created on the fly) and with real types, for example, when adding a scalar to an array. - dionys

Why is the sky blue? Hmm, yes, Rayleigh scattering. Not the point.

Because types are determined at runtime (exactly how it is clear from the context), and also implicitly converted.
For example, you can do so and there will be no mistakes:

 $string = 'Test'; $number = 42; print $string . $number . "\n"; # Test42\n 

http://goo.gl/uLMxf3

That says that Perl automatically understands the types, which is confirmed by the wiki:

All versions of Perl perform automatic data typing and automatic memory control.


Translation of one data type into another - for example, numbers into a string - occurs automatically at runtime, and impossible to execute data type transfers result in a fatal error.


Strong typing presupposes variables to be the whole existence of one type (or explicit cast), to use only those signatures that are described in functions, operator overload, if supported, must also be specified.
Etc.

  • String operator converts operands to strings, where is the implicit conversion here? It seems you just did not understand the question. - Smit Johnth

Because Perl is a dynamic language. Therefore, it has no types at all (in the understanding of C / C ++). In a sense - this is his advantage. Perl has contexts instead of types:

  • String
  • Numerical
  • Boolean
  • Scalar
  • List
  • Void (Empty)
  • Interpolating (double-quote context)

There are different operators for strings and numbers, so the conversion between them is not implicit.

No, conversion just happens implicitly. Just in the code we have to specify what we expect: strings or numbers. Without an additional operator, one would have to cram down crutches in some cases. And so everything is simple and beautiful:

 '1a' == '1b' # TRUE 1 == 1 '1a' eq '1b' # FALSE '1a', '1b' строки разные 1 == '1b' # TRUE 1 == 1 1 eq '1b' # FALSE '1', '1b' строки разные 
  • "Because Perl is a dynamic language. Therefore, it has no type at all" - you confuse weak and dynamic typing. "No, the conversion just happens implicitly. We just have to specify in the code what we expect: strings or numbers." - in my understanding this is an obvious conversion, since the type to convert to is explicitly specified by the programmer. - Smit Johnth