|
Posted by Bill H on June 1, 2008, 9:41 am
Please log in for more thread options
> For years I have always done various versions the following (and I
> know there is probably some perlish way of doing it better, but old
> habits die hard) to go through a list of data and build a string that
> contains only certain matched data:
>
> $stuff =3D "":
> foreach $temp (@dbf)
> {
> @rbf =3D split(/\t/,$temp);
> if($rbf[0] =3D=3D 0)
> {
> $stuff .=3D $temp."|";}
> }
>
> $stuff =3D substr($stuff,0,length($stuff) - 1);
>
> But I just realized about 5 minutes ago instead of pulling off the
> last usless "|" I could just replace $stuff =3D ""; with stuff =3D "|";
> and the last line with: $stuff =3D substr($stuff,1);
>
> And, while typing this I just realized I could do the above even
> better:
>
> foreach $temp (@dbf)
> {
> @rbf =3D split(/\t/,$temp);
> if($rbf[0] =3D=3D 0)
> {
> $cbf[@cbf] =3D $temp}
> }
>
> $stuff =3D join('|',@cbf);
>
> I am willing to bet now there is a one line command that would do all
> this.
>
> Bill H
I can throw a sort in that join and make it better (oh this is getting
fun now)
$stuff =3D join('|',sort @cbf);
Bill H
|