in reply to Why I can't fetch any special variables ?

$< doesn't get created automatically. Just like with any other variable, you need to use the G_ADD flag to create the var if it doesn't exist. The magic will be added automatically when it's created.

As for $^X, "^X" is a convenient way of writing Ctrl-X. Yes, you can use a real Ctrl-X after the $ in the code, and in fact, that's the real variable name. You'll need to pass "\cX" (or whatever the C equivalent is) to gv_fetchpv.

Replies are listed 'Best First'.
Re^2: Why I can't fetch any special variables ?
by PerlOnTheWay (Monk) on Sep 15, 2011 at 04:40 UTC

    It works by using "\030"

Re^2: Why I can't fetch any special variables ?
by PerlOnTheWay (Monk) on Sep 15, 2011 at 04:56 UTC

    Isn't the second parameter of gv_fetchpv the default value?

    How do you specify the G_ADD flag?

      Isn't the second parameter of gv_fetchpv the default value?

      Say again?

      What does it mean for a parameter to be a default value? C doesn't have optional parameters, so parameters can't even have default values in C.

      How do you specify the G_ADD flag?

      Use it instead of zero for the second argument.

Re^2: Why I can't fetch any special variables ?
by Anonymous Monk on Sep 15, 2011 at 04:48 UTC

    $< doesn't get created automatically.

    Sure it does  perl -le " print defined $<"

    As for $^X, "^X" is a convenient way of writing Ctrl-X. Yes, you can use a real Ctrl-X after the $ in the code, and in fact, that's the real variable name. You'll need to pass "\cX"c (or whatever the C equivalent is) to gv_fetchpv.

    $^X is the actual name of the variable, so no, you don't need to use \cX, you can use $^X, the actual name of the variable

      Sure it does perl -le " print defined $<"

      No, your use of it created it. Try

      perl -E'say for keys %::'

      $^X is the actual name of the variable

      Why are you contradicting two people without proof or argument?

      >perl -E"say ${ $::{'^X'} }" >perl -E"say ${ $::{qq{\cX}} }" ...\perl.exe

        Why are you contradicting two people without proof or argument?

        I'm not contradicting two people, i'm contradicting you, because perlvar contradicts you, you don't need \cX