skirrow has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have a flat-file text db for members information in the following format:
$name|$email|$username|$password|$blank|$date

What I want to do is have a page in my script with links such as:
a, b, c, ...., y, z, 0-9, Other
Click a would list all records with usernames starting with a or A. 0-9 lists all usernames starting with 0 - 9 and other would list usernames starting with non alphanumeric characters.
I want the records to be listed alphanumerically by username on output.

How do I do this? I thought using query strings would be useful because it would allow searches like a-e wouldn't it?

Also, on output I want to list all the fields in the db, not just the username.

Any help would be welcome! Thanks a lot.
- Neil

Replies are listed 'Best First'.
Re: Sorting Text DB
by TomK32 (Monk) on Jan 04, 2002 at 01:35 UTC
    Juerd already did a nice script (sorry I have no ++ left for today :-( but he didn't read the Other in a, b, c, ...., y, z, 0-9, Other and I think that's what makes it complicate.

    #!/usr/bin/perl use strict; use CGI qw(:standard); my $letter = param ('letter'); my @alluser; foreach ('a' .. 'z', '0-9', 'other') { print a({href=>"user.pl?letter=$_"}, $_), "\n"; // change user.pl +if needed } if ($letter =~ /^[a-z]$/i) { while (<DATA>) { push (@alluser, $_) if /^$letter/i; } } elsif ($letter eq '0') { while (<DATA>) { push (@alluser, $_) if /^[0-9]/i; } } elsif ($letter eq "other") { while (<DATA>) { push (@alluser, $_) if /^[^a-z^A-Z^0-9]/; } } else { while (<DATA>) { push (@alluser, $_); } } print sort @alluser; __DATA__ TomK32|abcdef tye|dude crazyinsomniac|chick juerd|dunno 007|Bond, James ~spacecowboy|wowawa *star*|shine
    Of course tested but written w/o CGI-knowledge and ugly output™.

    --
    paco for president
    TomK32 - just a geek trying to change the world

Re: Sorting Text DB
by rbc (Curate) on Jan 04, 2002 at 00:18 UTC
    You might want to look at grep.

    perldoc -f grep

    --
    Its like a dog that can sing and dance.
    It's remarkable because it can do it.
    Not that it can do it well.
A reply falls below the community's threshold of quality. You may see it by logging in.