Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; my %group; foreach my $line (<DATA>) { $line=~/(^\d{2})(\.*?)/g; my $account = $1; if($account=~/$group{$line}/g) { open my $fH, ">", "$account.txt" or die "Can't open or create ' +$account.txt'\n"; print $fH " $line \n"; close $fH; }else{ open my $fH, ">", "$account.txt" or die "Can't open or create ' +$account.txt'\n"; print $fH " $line \n"; close $fH } $group{$line}++; } __DATA__ 01 The quick red fox and dog as test. 02 Time flies like an arrow, fruit flies like a banana. 02 Time flies like an arrow, fruit flies like a banana. 03 Now is the time for all good men to come to the aid of their party. 01 The quick red fox jumped over the lazy brown dog. 01 The quick red fox jumped over the lazy brown dog. 02 Time flies like an arrow. 03 Now is the time for all good men to come to the aid of their party +and not going. 03 Now is the time for all.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Grouping unique lines into a file.
by Limbic~Region (Chancellor) on Apr 21, 2014 at 15:31 UTC | |
Re: Grouping unique lines into a file.
by ww (Archbishop) on Apr 21, 2014 at 15:53 UTC | |
by Anonymous Monk on Apr 21, 2014 at 17:27 UTC | |
by Not_a_Number (Prior) on Apr 21, 2014 at 17:34 UTC | |
by bigj (Monk) on Apr 21, 2014 at 18:20 UTC | |
Re: Grouping unique lines into a file.
by Laurent_R (Canon) on Apr 21, 2014 at 16:20 UTC |