Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: output using map

by AnomalousMonk (Bishop)
on Mar 07, 2020 at 00:46 UTC ( #11113924=note: print w/replies, xml ) Need Help??

in reply to Re: output using map
in thread output using map

I am not sure what you are trying to accomplish with the unpack A* code?

I think you're right that unpack is intended to chomp the newline (and maybe all whitespace?) from the end of each line.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $s = qq{abc defg hi \t \n}; my $t = unpack 'A*', $s; dd $t; " "abc defg hi"
(It's also unclear why chomp-ing would be necessary since lines are print-ed with a newline appended; no newline is appended in the OPed code, but maybe that potential problem was obscured by the fact that nothing was ever printed!)

Note that the keys (lines) of each file will be printed in random order.

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

Replies are listed 'Best First'.
Re^3: output using map
by Marshall (Abbot) on Mar 07, 2020 at 01:35 UTC
    I think you are correct about the intent of unpack. However this is a bad way to do it, if that is the intent. There might also be some issue related to UTF-8 filenames? But again this is not the "right way".

    I chomped the input lines and added back in a platform specific line ending in the print because in general, I don't store line endings in data structures because I strive for multi-platform code.

    Yes, foreach (keys %first_file) {} could be: foreach (sort keys %first_file) {}

      The sorting of keys (or, lines) does not help as the output would be out of sync from the order in a file. OP's code (after rewinding the file handle) would have printed the difference in lines in the same order as the lines appear in a file.

      Use of hash in OP was a handy way to keep track of lines seen. I think to keep the order of lines printed was the reason that coding_new opened the same files twice. I personally would have generated the hash with line as key & $. as value. To print, then I would have sorted on the hash value. I personally would have used Algorithm::Diff.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2020-06-04 20:14 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (35 votes). Check out past polls.