in reply to Print Behavior with Carriage Return
Note that you can open a file with CRLF line endings for reading with the :crlf IO layer. chomp will then remove both line ending characters.
johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -MData::Dumper -E + ' my $fileStr = qq{val1=key1\r\nval2=key2\r\nval3=key3\r\n}; open my $inFH, q{<:crlf}, \ $fileStr or die $!; my %hash; while ( <$inFH> ) { chomp; my( $v, $k ) = split m{=}; $hash{ $k } = $v; } close $inFH or die $!; print Data::Dumper ->new( [ \ %hash ], [ qw{ *hash } ] ) ->Sortkeys( 1 ) ->Dumpxs();' %hash = ( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3' );
I hope this is helpful.
Cheers,
JohnGG
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Print Behavior with Carriage Return
by haukex (Archbishop) on Jan 05, 2020 at 18:33 UTC |
In Section
Seekers of Perl Wisdom