Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Problem printing @arrays

by AnomalousMonk (Archbishop)
on Sep 04, 2021 at 03:58 UTC ( [id://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 5.8.9.5 (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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found