Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Get outputs from 2 commands and add to var

by trippledubs (Deacon)
on Nov 16, 2019 at 19:53 UTC ( #11108803=note: print w/replies, xml ) Need Help??

in reply to Get outputs from 2 commands and add to var

The binary operator dot takes two arguments and concatenates the data from the right operand to the left operand. Combine with an equal sign to concatenate and assign with one operator.

my $data = $self->cmd('show run', undef, $output_ref, qr/^(?![:!])/); $data .= 'appended data'; # Equivalent to $data = $data . 'appended data';

Additive Operators

my $data = $self->cmd('show run', undef, $output_ref, qr/^(?![:!])/); $data .= $self->cmd('some other command', undef, $output_ref, qr/^(?![ +:!])/);

You also have to think about context. You probably don't want to append a list to a scalar. If $self->cmd returns a list, that's what you would be doing.

use strict; use warnings; sub something { return (3,4,5) }; my $x = 'some data'; #scalar $x .= something; #list print $x; # some data5 print "\n"; print something; # 345

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11108803]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2020-10-29 02:09 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (266 votes). Check out past polls.