#!/usr/bin/perl -w use strict; my @file; while(<DATA>){ chomp; push @file,$_; } &getClients; #---------------------- sub getClients{ my @tuples = map {[split /\s+/, $_]} grep { !/^(?:#|$)/ } @file; foreach(sort {$a->[1] cmp $b->[1]} @tuples){ my ($cltnbr, $cltname, $clNum) = @$_; print "<a href='#' title='$cltnbr' name='$cltname $clNum' oncl +ick='fillText(this);'>$cltname $clNum</a><br />"; print qq|\n|; } } 1; __DATA__ 001 client 1 002 client 2 003 client 3
Which produces:
<a href='#' title='001' name='client 1' onclick='fillText(this);'>clie +nt 1</a><br /> <a href='#' title='002' name='client 2' onclick='fillText(this);'>clie +nt 2</a><br /> <a href='#' title='003' name='client 3' onclick='fillText(this);'>clie +nt 3</a><br />
Now, instead of using a global variable like the above you should pass it into the routine as a reference.
Celebrate Intellectual Diversity
In reply to Re: sorting a file
by InfiniteSilence
in thread sorting a file
by mooker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |