Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Why not perl have raw/native type

by Corion (Pope)
on Jan 07, 2020 at 09:36 UTC ( #11111112=note: print w/replies, xml ) Need Help??


in reply to Why not perl have raw/native type

Basically since Perl is highly dynamic, you can't prevent somebody from doing:

my $ref; { my native str $bb = 'hello world'; $ref = \$bb; } print $$ref;

Perl expects any variable to be at least of type SV. The closest you can get to a "native" variable is to use the PV slot of the variable and point it to your raw memory. You will still get reference counting and everything, but Perl expects all variables to support that.

Also note that by carefully looking at the code path, you can often prevent (needless) copying of data, for example by using DBI bind parameters instead of using ->fetchrow.

Replies are listed 'Best First'.
Re^2: Why not perl have raw/native type
by LanX (Cardinal) on Jan 09, 2020 at 04:25 UTC
    > you can't prevent somebody from doing:

    Actually, all informations are available at compile time ...

    Why shouldn't Perl be able to reject it, unless the reference $ref is also typed?

    But maybe I'm missing the OP's intention?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Actually, all informations are available at compile time ...

      Divining that information is the topic of Escape Analysis, and its far from trivial to find what values will remain local to a subroutine in the general case.

      If you want to put more restrictions on the "native" type, maybe you can make this easier, but that amounts to basically having a second set of data types that are not interoperable with the rest of Perl.

        Well, my point is that there is a difference between
        • "you can't"
        • "it is not trivial"

        Actually I'd prefer to see a use case from the OP before continuing further.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      How about:
      # foo() is a sub from a 3rd party library you have no control over sub foo { my $r = \$_[0] } my native str $s = "..."; foo($s);

      Dave.

        Same xxx other colour:

        foo needs a function signature with the right type.

        And yes I know that subs can be redefined, but change of prototype is also emitting a warning.

        Really complicated are lvalue situations like aliasing!

        But hey, I never said it's easy... ;)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2020-11-27 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?