in reply to rearranging text
#!/usr/bin/perl -w use strict; my $someDatFile = 'datfile.dat'; #the file you need read in open( DATFILE, $someDatFile ) or die "Cannot open $someDatFile"; my $currentPrefix; while( <DATFILE> ) { my( $prefix, $postfix ) = split ( /,/, $_ ); &cleanUp( \$prefix ); &cleanUp( \$postfix ); if( ( !$currentPrefix ) or ( $currentPrefix ne $prefix ) ) { if( $currentPrefix ) { print "\n"; } $currentPrefix = $prefix; print "$prefix, $postfix"; } else { print ", $postfix"; } } print "\n"; close( DATFILE ); sub cleanUp { my $ref = shift; $$ref =~ s/^\s*//; $$ref =~ s/\s*$//; }
|
|---|