Assuming DATA is your file handle to the list of users:
# store name list in %hash, where key is name or number
# and value is array of actual names
while( <DATA> ) {
chomp;
# does name have proper number?
if( /(00\d+)/ ) {
$key = $1;
next if !/^(ct|ma|mb)/; # skip those that don't begin ct,ma,mb
}
else {
$key = $_; # for all others use name itself
}
# add to hash--we have to check the key to avoid reference errors
if( exists( $hash{$key} ) ) { # already added once
push @{$hash{$key}}, $_;
}
else { # first time
$hash{$key} = [$_];
}
}
# now you have the data organized, To view:
foreach ( sort keys %hash ) {
print "$_ = ", join( ', ', @{$hash{$_}} ), "\n";
}
__END__
on 5/10/02 4:52 AM, [EMAIL PROTECTED] purportedly said:
> I have a file with a list of users.Some of the user names are like this:
>
> ct002345
> ct000123
> ma005678
> ma009876
> mb000867
> mb002412
> sa000100
> sb000003
> sg000072
>
> I need to extract just the number(there is 00 before each number and I
> want it too) of "ct , ma , mb"(no "sa , ecc.")and all the other users
> that are in the list:
> example
>
> abelar --> abelar
> aci09 --> aci09
> ct001234 --> 001234
> ma000234 --> 000234
> sg000072 --> nothing
>
> This is the first step.Then I need to make a new file with every normal
> name and for each number extacted the three possibilities(ct , ma , mb)
>
> example
>
> abelar --> abelar
> 001234 --> ct001234
> ma001234
> mb001234
>
> I'm trying from a week but pattern matching is not so simple for
> me.Please help me.Thanks
>
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"