Access array element in Perl

212 views Asked by At

Dumper(@releases) has the following

$VAR1 = '\projects\proj mypac : test / 04.00.00; 0';

When I do print ( $releases[0]) it gives

\projects\proj mypac : test / 04.00.00; 0

I want individual elements like

$releases[0] = \projects\proj;
$releases[1] = mypac;
$releases[2] = mypac;
$releases[3] = 04.00.00;
$releases[4]  = 0;

How can I achieve this?

1

There are 1 answers

3
Miller On BEST ANSWER

Just split your string.

use strict;
use warnings;

my $string = '\projects\proj mypac : test / 04.00.00; 0';

my @fields = split m{\s*[:/;]?\s+}, $string;

use Data::Dumper;
print Dumper \@fields;

Outputs:

$VAR1 = [
          '\\projects\\proj',
          'mypac',
          'test',
          '04.00.00',
          '0'
        ];