[Solved] I am not getting what this code does in perl [closed]


Here is an explanation:

foreach (@a) {                  # loop on all elements of array @a
    if ( $_ =~ m/active/ ) {    # if current element contains 'active'
        s/ *//g;                # removes all spaces
        s/\r//;                 # remove carriage return
        my @v = split(/\-/);    # split on dash 
        $_cfg{$v[0]} = $v[1];   # populates the hash %_cfg where the key is 
                                # what there is before the first dash
                                # and value is what is between the first and the second dash
                                # or end of string
    }
}

If your array @a contains for example:

my @a = (
    'active-true',
    'this is not  - active'
    'whatever',
);

Then the hash %_cfg will contain:

%_cfg =
(
    active => 'true',
    thisisnot => 'active',
);

2

solved I am not getting what this code does in perl [closed]