When does Perl impose a string context?

It seems that the context of the string (while the real thing is mentioned in the chapter "Programming Perl" "2.7.1. Scalar and the context of the list" as an expression of the scalar context) is not documented anywhere where I could be found on Perldoc.

Obviously, some things in Perl (for example, the operator eqor qq // quoting interpolation) force a value in the context of a string.

When does Perl enter a string context?

perldoc seems to not contain a useful answer .

+4
source share
1 answer

Perl PV ( ) , , Perl . , , perlguts, perldata , , perlop. , , , , , , .

, $var = 15, $var, , if( $var eq '15' ) {...}, 15 PV .

, :

  • (eq, ne, ge, le, lt, gt)

  • (=~, !~)

  • (qq{$var}, "$var", qx/var/ )

  • (m/$interpolated/, s/$interpolated//, qr/$interpolated/)

  • <<"HERE" ( doc )

  • $hash{$stringified_key}.

  • . .

  • Perl, bitwise, &., |., ^. ~. , &.= .

  • vec .

, . , "". , , JSON, JSON, , , PV , , .

, Devel::Peek, Perl, Perl 5.6.0 :

use Devel::Peek;                    

my $foo = 12;                       

print "Initial state of \$foo:\n";  
Dump($foo);                         

my $bar = "$foo";                   

print "\n\nFinal state of \$foo:\n";
Dump($foo);                         

, :

Initial state of $foo:
SV = IV(0x56547b4bb2a0) at 0x56547b4bb2b0
  REFCNT = 1
  FLAGS = (IOK,pIOK)
  IV = 12


Final state of $foo:
SV = PVIV(0x56547b4b5880) at 0x56547b4bb2b0
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 12
  PV = 0x56547b4ab600 "12"\0
  CUR = 2
  LEN = 10

, PV, POK , CUR LEN , .

+7

All Articles