Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8353725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:20:46+00:00 2026-06-09T09:20:46+00:00

I like to capture all global variables from an external Perl script with Perl.

  • 0

I like to capture all global variables from an external Perl script with Perl. Currently I am hanging around the type detection.

How to determine the correct data type (”, ‘SCALAR’, ‘HASH’, ‘ARRAY’, ‘CODE’)?

Parser script:

my %allVariables = ();
{
     do "scriptToBeParsed.pl";
     foreach my $sym ( keys %main:: ) {
         # Get all normal variables and scalar/hash/array references:
        if ( ref( *{"$sym"} ) =~ m/^(?:|SCALAR|HASH|ARRAY)$/ ) {
            $allVariables{"$sym"} = *{"$sym"};
        }
    }
}

Script to be parsed:

$someVariable1 = 'Yes, I like to be captured';
$otherVariable2 = \'And I also want to be captured';
%anotherVariable3 = ( 'Capture' => 'me' );
@lameVariable4 = ( 'Capture', 'me' );
$fooVariable5 = { 'Capture' => 'me' };
$barVariable6 = [ 'Capture', 'me' ];
$subVariable7 = sub { return "Don't capture me!" };
sub dontCaptureMe { return "Don't capture me!" }

In my example ref( *{"$sym"} ) returns always ‘GLOB’ (of course).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:20:47+00:00Added an answer on June 9, 2026 at 9:20 am

    Another approach would be to use the has-like access of the typeglob, which is explained in Chapter 8 of brian d foy’s Mastering Perl on page 131f.

    package test;
    no strict;
    no warnings; 
    
    $someVariable1 = 'Yes, I like to be captured';
    $otherVariable2 = \'And I also want to be captured';
    %anotherVariable3 = ( 'Capture' => 'me' );
    @lameVariable4 = ( 'Capture', 'me' );
    $fooVariable5 = { 'Capture' => 'me' };
    $barVariable6 = [ 'Capture', 'me' ];
    $subVariable7 = sub { return "Don't capture me!" };
    sub dontCaptureMe { return "Don't capture me!" }
    
    say $dontCaptureMe;
    my %allVariables = ();
    {
      do "scriptToBecomeParsed.pl";
      foreach my $sym ( keys %test:: ) {
        for (qw( SCALAR HASH ARRAY CODE IO)) {
          if (*{"$sym"}{$_}) {
            $allVariables{$_}->{"$sym"} = *{"$sym"}{$_};
          }
        }
      }
    }
    
    print Data::Dumper::Dumper \%allVariables;
    

    This will produce the following output:

    $VAR1 = {
              'CODE' => {
                          'dontCaptureMe' => sub { "DUMMY" }
                        },
              'ARRAY' => {
                           'lameVariable4' => [
                                                'Capture',
                                                'me'
                                              ]
                         },
              'HASH' => {
                          'anotherVariable3' => {
                                                  'Capture' => 'me'
                                                }
                        },
              'SCALAR' => {
                            'someVariable1' => \'Yes, I like to be captured',
                            '__ANON__' => \undef,
                            'subVariable7' => \sub { "DUMMY" },
                            'dontCaptureMe' => \undef,
                            'otherVariable2' => \\'And I also want to be captured',
                            'BEGIN' => \undef,
                            'barVariable6' => \[
                                                  'Capture',
                                                  'me'
                                                ],
                            'anotherVariable3' => \undef,
                            'lameVariable4' => \undef,
                            'fooVariable5' => \{
                                                  'Capture' => 'me'
                                                }
                          }
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a php script that can capture a page from
For performance testing, I would like to capture some traffic from a production server
I will like to take a screen capture without a window. I currently hide
I would like to run several commands, and capture all output to a logfile.
I'm attempting to pass perl variables into a system command and then capture the
Is it possible to capture all 500 errors in Classic ASP at a global
Is there a way in PHP to capture all post and get variables that
Trying to use Excel VBA to capture all the file attributes from files on
I have a url string from which I want to capture all the words
I would like to capture all incoming HTTP packets of my machine. To do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.