Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: sort without ignoring hyphens
tc314@hotmail.com wrote:
> On Mar 30, 10:57 pm, kra...@telus.net (John W. Krahn) wrote: 
>
> I'm looking for the perl way of comparing strings.
>
> Your posted code 'diff says memory exhausted need help with perl
> Options'
> is the basis I want to build from.
> But it appears the gt,eq,lt comparisons ignore the hyphens in the
> strings.

No they do not.

> I really want to avoid slowing things to a crawl by doing brute force
> byte comparisons rather than string compares.

Perl's string comparison operators *do* compare each byte.

> (I'm really looking for a minimal patch to your code to produce the
> desired results.)

perldoc -q "How do I handle binary data correctly"
perldoc perllocale


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
04-01-08 09:04 AM


Re: sort without ignoring hyphens
tc314@hotmail.com schreef:
> John W. Krahn:
 
>
> I'm looking for the perl way of comparing strings.
>
> Your posted code 'diff says memory exhausted need help with perl
> Options'

Maybe your shell requires dquotes?

--
Affijn, Ruud

"Gewoon is een tijger."

Report this thread to moderator Post Follow-up to this message
Old Post
Dr.Ruud
04-02-08 12:05 AM


Re: sort without ignoring hyphens
On Mar 29, 3:19=A0pm, kra...@telus.net (John W. Krahn) wrote:
> tc...@hotmail.com wrote: 
>
> Please provide an *example* of your data, what it would look like if
> sorted "properly", and what it actually looks like after being sorted.
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- =[/color
]
Larry Wall

Given my data: (echo.txt)
21A
22A
2-4A
2-2A
23A
2-3A
08E
08F
08G
08GA
08H
08-J

I want perl (and linux sort) to see its order as:
08-J
08E
08F
08G
08GA
08H
2-2A
2-3A
2-4A
21A
22A
23A

However (on my system):
1) linux sort: sort echo.txt
produces the undesired result:
08E
08F
08G
08GA
08H
08-J
21A
22A
2-2A
23A
2-3A
2-4A

2) linux sort with -n: sort -n echo.txt
produces the undesired result:
2-2A
2-3A
2-4A
08E
08F
08G
08GA
08H
08-J
21A
22A
23A

3) perl's sort produces the DESIRED result
perl -le'@x =3D qw[21A 22A 2-4A 2-2A 23A 2-3A 08E 08F 08G 08GA 08H 08-
J]; print for sort @x'
08-J
08E
08F
08G
08GA
08H
2-2A
2-3A
2-4A
21A
22A
23A


So, how do I write a perl script to use in place of linux sort since
perl's sort
produces the desired results?

I want perlsort to accept input from STDIN or a filename as an argv.
I don't care about any command line options since perl seems to do
exactly
what I desire. (I thought perl's comparisons were wrong because I used
files sorted
by linux sort, my mistake.)

My files are significantly larger than physical memory.

Any help is appreciated.


Report this thread to moderator Post Follow-up to this message
Old Post
tc314@hotmail.com
04-02-08 03:02 AM


Re: sort without ignoring hyphens
LC_ALL=C sort echo.txt

tc314@hotmail.com wrote:
> On Mar 29, 3:19 pm, kra...@telus.net (John W. Krahn) wrote:
> 
>
> Given my data: (echo.txt)
> 21A
> 22A
> 2-4A
> 2-2A
> 23A
> 2-3A
> 08E
> 08F
> 08G
> 08GA
> 08H
> 08-J
>
> I want perl (and linux sort) to see its order as:
> 08-J
> 08E
> 08F
> 08G
> 08GA
> 08H
> 2-2A
> 2-3A
> 2-4A
> 21A
> 22A
> 23A
>
> However (on my system):
> 1) linux sort: sort echo.txt
> produces the undesired result:
> 08E
> 08F
> 08G
> 08GA
> 08H
> 08-J
> 21A
> 22A
> 2-2A
> 23A
> 2-3A
> 2-4A
>
> 2) linux sort with -n: sort -n echo.txt
> produces the undesired result:
> 2-2A
> 2-3A
> 2-4A
> 08E
> 08F
> 08G
> 08GA
> 08H
> 08-J
> 21A
> 22A
> 23A
>
> 3) perl's sort produces the DESIRED result
> perl -le'@x = qw[21A 22A 2-4A 2-2A 23A 2-3A 08E 08F 08G 08GA 08H 08-
> J]; print for sort @x'
> 08-J
> 08E
> 08F
> 08G
> 08GA
> 08H
> 2-2A
> 2-3A
> 2-4A
> 21A
> 22A
> 23A
>
>
> So, how do I write a perl script to use in place of linux sort since
> perl's sort
> produces the desired results?
>
> I want perlsort to accept input from STDIN or a filename as an argv.
> I don't care about any command line options since perl seems to do
> exactly
> what I desire. (I thought perl's comparisons were wrong because I used
> files sorted
> by linux sort, my mistake.)
>
> My files are significantly larger than physical memory.
>
> Any help is appreciated.
>
>
>


Report this thread to moderator Post Follow-up to this message
Old Post
Matthew Whipple
04-03-08 12:18 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): « 1 [2]
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:40 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.