0

i am trying to write a perl script where i am reading the data into an array which is an output of some command like this:

my @a = system "p4 changes -u";

now that data has been into the array @a it looks something like this:

change 256789 on date.. by user@workspace 'some description'
change 256788 on date.. by user@workspace 'some description'
..........................................................
...........................................................
.
.
..
...

there are so many lines

now what i would like to do is get the "some description" field of each entry into another array and then append some common text to it.
any ideas how to do it , i am relatively new to Perl so not getting much ideas how to do it.

2 Answers 2

2

system executes the command but does not capture the output. To capture output you can use backticks(`) or the qx operator.

#!/usr/bin/env perl

use strict;
use warnings;

my @descriptions;
for (qx{p4 changes -u}) {
    chomp;
    push @descriptions, /(?<=')(.+)(?=')/;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe as this:

@b = map { /('[^']+')/; "abc $1 xyz"; } @a;
print "$_\n" for @b;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.