access(2) - perldoc - phpman

Markdown | JSON | MCP    


Found in /usr/share/perl/5.34/pod/perlfaq4.pod
  How can I access or change N characters of a string?
    You can access the first characters of a string with substr(). To get
    the first character, for example, start at position 0 and grab the
    string of length 1.

        my $string = "Just another Perl Hacker";
        my $first_char = substr( $string, 0, 1 );  #  'J'

    To change part of a string, you can use the optional fourth argument
    which is the replacement string.

        substr( $string, 13, 4, "Perl 5.8.0" );

    You can also use substr() as an lvalue.

        substr( $string, 13, 4 ) =  "Perl 5.8.0";

Found in /usr/share/perl/5.34/pod/perlfaq7.pod
  How can I access a dynamic variable while a similarly named lexical is in scope?
    If you know your package, you can just mention it explicitly, as in
    $Some_Pack::var. Note that the notation $::var is not the dynamic $var
    in the current package, but rather the one in the "main" package, as
    though you had written $main::var.

        use vars '$var';
        local $var = "global";
        my    $var = "lexical";

        print "lexical is $var\n";
        print "global  is $main::var\n";

    Alternatively you can use the compiler directive our() to bring a
    dynamic variable into the current lexical scope.

        require 5.006; # our() did not exist before 5.6
        use vars '$var';

        local $var = "global";
        my $var    = "lexical";

        print "lexical is $var\n";

        {
            our $var;
            print "global  is $var\n";
        }

  How can I catch accesses to undefined variables, functions, or methods?
    The AUTOLOAD method, discussed in "Autoloading" in perlsub lets you
    capture calls to undefined functions and methods.

    When it comes to undefined variables that would trigger a warning under
    "use warnings", you can promote the warning to an error.

        use warnings FATAL => qw(uninitialized);


Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 22:22 @216.73.216.151 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 TransitionalValid CSS!