in reply to Re^4: Unicode issues with emc uemcli
in thread Unicode issues with emc uemcli
Of course, a loop would be a bit more elegant, here's just one example.
use warnings; use strict; use IPC::Run3; use Encode qw/decode/; my @outputs; for my $loc ('/sys/general', '/env/bat', '/env/ps') { run3 ['uemcli','-d',$vnxe_ip,'-u',$username,'-p',$password, $loc,'show','-detail'], undef, \my $out; my $str = decode('UTF-16', $out, Encode::FB_CROAK); push @outputs, $str; } print $outputs[0], "\n"; open my $fh, '>', $textfile or die "$textfile: $!"; print $fh $outputs[1]; close $fh;
Update: Note that both prints in this example assume you don't have any Unicode (non-ASCII) characters in the strings (as your sample data shows). If you did, you'd need to set an encoding on the filehandles you're writing the data to - that's STDOUT, with for example use open qw/:std :utf8/; or several variations on that, and for filehandles, for example open my $fh, '>:encoding(UTF-8)', $filename or die "$filename: $!";.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Unicode issues with emc uemcli
by pritesh_ugrankar (Monk) on Sep 08, 2020 at 16:28 UTC | |
by haukex (Archbishop) on Sep 08, 2020 at 16:53 UTC | |
by pritesh_ugrankar (Monk) on Sep 08, 2020 at 18:47 UTC | |
by haukex (Archbishop) on Sep 08, 2020 at 20:29 UTC |