Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Bug in Sort::Fields?

by cmv (Chaplain)
on Jul 20, 2010 at 19:14 UTC ( #850495=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Bug in Sort::Fields?
in thread Split(), Initial Spaces, & a limit?

Yes, I agree with you that the key cannot vary by row.

Since this is what Sort::Fields is doing, are you agreeing with me that this is a bug in that module?

As I implied earlier, the module should sort the exact same data, the same way, no matter where that data shows up (field 1, field 2, or field N).

Thanks

-Craig

update: Ah, sorry, you were still editing, and added more to the reply while I was responding.

I think my point is that Sort::Fields will "do the right thing" if the data containing initial spaces is in any place other than field 1. If the data is in field 1, then it does something different.

I believe this is because the author specifically uses /\s+/ as the field delimiter in his code. This works fine for every field except field 1 (as shown by the discussion at the beginning of this post). I would like to see this module do the same thing on the same data, no matter what field it show up in.

I believe this should be easily fixable, by replacing the /\s+/ with /' '/, as you showed me in an earlier post. I just can't figure out how to do that in his code. I also don't know what side effects that would have.


Comment on Re^4: Bug in Sort::Fields?
Re^5: Bug in Sort::Fields?
by ikegami (Pope) on Jul 20, 2010 at 19:17 UTC

    Yes, I agree with you that the key cannot vary by row.

    Then don't pass such data to Sort::Fields.

    are you agreeing with me that this is a bug in that module?

    Most definitely not. It's sorting using the specified field as the key. It's not its fault you didn't put the key in that field.

Re^5: Bug in Sort::Fields?
by ikegami (Pope) on Jul 20, 2010 at 19:28 UTC

    I would like to see this module do the same thing on the same data, no matter what field it show up in.

    That's exactly what it does.

    What's left of the first space group is the first field.
    What's left of the second space group is the second field.
    What's left of the third space group is the third field.

    You're the one who wants to treat the first field specially. That's not a problem, but you'll have to do it yourself.

      ikegami-

      This is an extremely interesting discussion for me, thanks for staying with it.

      It seems that my perception is that the first field is not being treated the same, and I'm wishing it was.

      I'm starting to understand that your perception is that it is being treated the same.

      I offer this bit of code to try and show my perspective:

      use strict; use warnings; use Sort::Fields; use Data::Dumper; my @data = `ls -ls | tail -5`; chomp(@data); print "Field 1 sort:\n", Dumper(fieldsort( ['1n'], @data)); @data = `ls -l | tail -5`; chomp(@data); print "Field 5 sort:\n", Dumper(fieldsort( ['5n'], @data));
      The field 1 sort is not sorted at all. We know why, we've been beating that poor horsie all afternoon.

      The field 5 sort is sorted correctly. Only because field 1 didn't have any leading spaces in any of the lines.

      What I'm hearing you say is "As long as there are no leading spaces in field 1, Sort::Fields will treat all fields the same way".

      What I believe I'm saying is "If Sort::Fields can handle initial spaces in field 5, why does it handle initial spaces in field 1 differently?".

      Is that a fair assessment?

        The field 1 sort is not sorted at all. We know why, we've been beating that poor horsie all afternoon.

        It is being sorted correctly. Empty strings are placed first. You're miscounting the fields.

        The field 5 sort is sorted correctly.

        You say that because you haven't seen the following example:

        use strict; use warnings; use Sort::Fields; use Data::Dumper; my @data = split /\n/, <<'__EOI__'; 10 0 0 6 4 1 0 0 5 3 __EOI__ print "Field 1 sort:\n", Dumper(fieldsort( ['1n'], @data)); print "Field 5 sort:\n", Dumper(fieldsort( ['5n'], @data)); __END__ Field 1 sort: $VAR1 = ' 1 0 0 5 3'; $VAR2 = '10 0 0 6 4'; Field 5 sort: $VAR1 = '10 0 0 6 4'; $VAR2 = ' 1 0 0 5 3';

        Field 1: "" < 10
        Field 5: 4 < 5

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-04-18 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls