Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Problem printing @arrays

by AnomalousMonk (Bishop)
on Sep 04, 2021 at 03:58 UTC ( #11136432=note: print w/replies, xml ) Need Help??

in reply to Problem printing @arrays

I suspect you are reading a file created with \r\n (carriagereturn-linefeed) line endings (e.g., on a Windows system) on a system (e.g., *nix) that uses \n (linefeed) line endings. On the reading system, the line-feed is chomp-ed off leaving the carriage-return. This can be simulated with something like:

Win8 Strawberry (32) Fri 09/03/2021 23:52:22 C:\@Work\Perl\monks >perl use strict; use warnings; use Data::Dump qw(dd); my $data = <<"EOD"; AA\r AAH\r AAHED\r AAHING\r AAHS\r AAL\r ZYTHUMS\r ZYZZYVA\r ZYZZYVAS\r ZZZ\r ZZZS\r EOD open my $fh, '<', \$data or die $!; my @words = <$fh>; close $fh; dd \@words; chomp @words; dd \@words; print "@words\n"; ^Z [ "AA\r\n", "AAH\r\n", "AAHED\r\n", "AAHING\r\n", "AAHS\r\n", "AAL\r\n", "ZYTHUMS\r\n", "ZYZZYVA\r\n", "ZYZZYVAS\r\n", "ZZZ\r\n", "ZZZS\r\n", ] [ "AA\r", "AAH\r", "AAHED\r", "AAHING\r", "AAHS\r", "AAL\r", "ZYTHUMS\r", "ZYZZYVA\r", "ZYZZYVAS\r", "ZZZ\r", "ZZZS\r", ] ZZZSYVAS

Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Problem printing @arrays
by Anonymous Monk on Sep 04, 2021 at 04:30 UTC
    you forgot to give a solution... :crlf
Re^2: Problem printing @arrays
by sbrothy (Acolyte) on Sep 04, 2021 at 15:51 UTC

    I'll have to study this a little more. The dd command isn't what I would call intuitive. I'm sure, though, that I'll learn something by it I cannot learn any other way; much like holding a cat by the tail :)

    Regards, sbrothy.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2022-01-19 15:16 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (55 votes). Check out past polls.