Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Fake JAPH

by Anonymous Monk
on Dec 14, 2004 at 12:43 UTC ( [id://414693]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Fake JAPH
in thread Fake JAPH

What I'd like to stress is that in Perl (5, that is!) there's hardly anything like a *string* context

Actually, there is, and lots and lots of it. Perl could not do automatical transformation between numerical values and string values if it wasn't for string context:

#!/usr/bin/perl use strict; use warnings; use Devel::Peek; my $var = 13; Dump($var); print "\n\n"; my $dummy = q...$var; Dump($var); __END__ SV = IV(0x8194b2c) at 0x8193d70 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 13 SV = PVIV(0x8184448) at 0x8193d70 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,POK,pIOK,pPOK) IV = 13 PV = 0x818bca0 "13"\0 CUR = 2 LEN = 3
As you can see, the use of $var in string context caused the upgrade from an IV to a PVIV.

String context is also what triggers the stringify overload in objects (if defined).

Replies are listed 'Best First'.
Re^4: Fake JAPH
by blazar (Canon) on Dec 16, 2004 at 13:12 UTC
    What I'd like to stress is that in Perl (5, that is!) there's hardly anything like a *string* context
    Actually, there is, and lots and lots of it. Perl could not do automatical transformation between numerical values and string values if it wasn't for string context:
    Indeed Perl does magic dwimmeries with automatic conversions between numerical and string values depending on how these are used, but what I meant is that only to a very limited extent there does exist a well-definite concept of "string (or numerical) context" comparable to, say, "scalar (or list) context". As an example, quoting from 'perldoc perlvar':
    $!      If used numerically, yields the current value of the C "errno"
            variable, or in other words, if a system or library call fails,
            it sets this variable.  This means that the value of $! is
            meaningful only immediately after a failure:
    As you can see, it consistently avoids speaking of "numerical context". Incidentally my stress on Perl5 was due to the fact that Perl6 is supposed to have such contexts instead (and to support them unambiguously!)

    Also compare e.g.

    http://www.google.it/search?q=%22string+context%22+site:perldoc.com
    with
    http://www.google.it/search?q=%22scalar+context%22+site:perldoc.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://414693]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found