Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort question 1

Status
Not open for further replies.

PerlElvir

Technical User
Aug 23, 2005
68
Hi all, this forum help me a lot of time I hope now will be same :eek:)

Ok I have in one row name with few value so I want that value become for that name one by one

exampl:

Cris 25 13 12

and I want to have

Cris 25
Cris 13
Cris 12
 
Code:
@data=split / /, $line;
$title=pop @data;
foreach (@data) {
  print "$title\t$_\n";
}

HTH
--Paul

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Just after copping the sort requirement.

forget pop, use shift, and after shifting sort the array if needs be.

Caffeine deficiencies should be avoided at all costs ;-)

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 


Sorry dude, but I didnt explain well this situation, but thanx on replay ;)

Look this, I have 4 variables
$Cris, $var1, $var2, $var3 and now I want to have in my insert in database :

1row - $Cris(field1), $var1(field2)
2row - $Cris(field1), $var2(field2)
3row - $Cris(field1), $var3(field2)

 
What Paul meant:

Code:
@data = split / /, $line;
$title = shift @data;
for (sort {$b <=> $a} @data) {
  print "$title\t$_\n";
}

or a bit shorter:
Code:
my ($title,@numbers) = split / /, $line;
for (sort {$b <=> $a} @numbers) {
  print "$title\t$_\n";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top