stdout - Can't figure out why perl prints out newline and then data instead of vice versa -


well, code pretty simple. should print content + \n result somehow reversed.

here code:

#!/usr/bin/perl -w   use strict;  $founds;   while (<>){      $$founds{$2} = $& while  m/([a-z]{3})([a-z])([a-z] {3})/g;                                }  print sort keys %$founds, "\n"; 

and result is:

(here newline)   abcdefghijklmnopqrstuvwxyz 

hope happens configurations (if want download file used on code go here)

anyway, know it?

p.s: regex doesn't allow newline characters, it's unlikely problem belongs it.

the reason newline first include in sort due lack of parentheses. instead:

print sort(keys %{$founds}), "\n"; 

the newline comes first coincidence (or rather, virtue of being whitespace character amongst non-whitespace).

for clarification:

my %found = ( foo => 1, bar => 1 );   # keys returns "foo", "bar" print sort keys %found, "\n";         # sort gets "foo", "bar", "\n"          # ^^^^^^^^^^^^^^^^^----------- arguments sort() 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -