Re: sort after split
by dragonchild (Archbishop) on Dec 05, 2007 at 19:57 UTC
|
@fields = sort { $a cmp $b } split /\t/, $entry;
sort
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] [d/l] |
|
|
Thanks Dragonchild,
I read that in perldoc, however, my output is just the parens, like so:
Any idea why? Thanks!
Thanks!
| [reply] |
|
|
Check to make sure $entry has what you think it does. That sounds like $entry is "\t\t" (or somesuch). Try adding the -w flag.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] |
|
|
Re: sort after split
by ysth (Canon) on Dec 06, 2007 at 05:08 UTC
|
It sounds like you what you've tried is sorting the fields for each logfile.log record, when what it sounds
like to want to do is sort the records themselves.
To do that, you need to save them all and then sort them, something like this:
while (my $entry = <DB>) {
chomp(my @fields = split(/\t/, $entry));
push @records, \@fields;
}
@records = sort { $a->[1] cmp $b->[1] } @records;
for my $fields (@records) {
print <<ENDHTML;
<li><a href="#$fields->[0]">$fields->[0] ($fields->[1])</a></li>
ENDHTML
}
(untested, and making some guesses about what you want)
| [reply] [d/l] |
|
|
BINGO! Thanks ysth!
After some minor tweaking I have it working beautifully now. Thanks to you and everyone else. have a good day!
LakeTrout
| [reply] |
Re: sort after split
by Roy Johnson (Monsignor) on Dec 05, 2007 at 20:41 UTC
|
| [reply] |
|
|
Hi Roy,
Thanks for the help. The params 0/1 ask for a company name and country. For privacy sake, I'll just give the first letter. Here is an example of what I get now:
J... ( Korea )
L... ( Korea )
A... ( France )
G... ( USA )
I... ( France )
M... ( Brazil )
This is what I would like:
A... ( France )
G... ( USA )
I... ( France )
J... ( Korea )
L... ( Korea )
M... ( Brazil )
Does this help? Thanks! | [reply] [d/l] [select] |
|
|
| [reply] |
Re: sort after split
by aquarium (Curate) on Dec 05, 2007 at 22:21 UTC
|
| [reply] |
|
|
Thanks Aquarium,
I tried chomping then entry, but my list still prints in a sequential manner. Losing my mind :)
open (DB1,"logfile.log") or die("There was a problem opening the file.
+");
while ($entry=<DB1>) {
chomp $entry;
@fields = sort { $a cmp $b } split /\t/, $entry;
#@fields=split(/ /,$entry);
#chomp @fields;
foreach $entry (@fields){
$_ =~ s/\n/\,/;
}
Any other ideas? I really appreicate your help all. Thank a Million.
lT | [reply] [d/l] |
|
|
| [reply] |