Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Get outputs from 2 commands and add to var

by trippledubs (Deacon)
on Nov 16, 2019 at 19:53 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found