0

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?

Yamuna
  • 71
  • 1
  • 2
  • 13

1 Answers1

3

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'
        ];
Miller
  • 34,962
  • 4
  • 39
  • 60
  • @releases is an array so I am afraid I couldn't use the solution – Yamuna Aug 20 '14 at 05:34
  • 3
    Yes, `@releases` is a 1 element array. Therefore just access the scalar using `$releases[0]`. Perhaps read: [Modern Perl Book - The Perl Language](http://modernperlbooks.com/books/modern_perl_2014/03-perl-language.html) – Miller Aug 20 '14 at 05:36
  • I have used first element of array in the place of $string and got it working :-) Thank you :) – Yamuna Aug 20 '14 at 05:37