Kevin Pfeiffer wrote:
>
> In article <[EMAIL PROTECTED]>, John W. Krahn wrote:
> >
> > Ok, but it may be a bit long. :-)
> >
> > my $file = 'file.txt';
> >
> > my @unique = do {
> > open my $fh, '<', $file or die "Cannot open $file: $!";
> > my %seen;
> > grep !$seen{$_}++, <$fh>
> > };
>
> How much different is:
>
> my $file = 'file.txt';
> {
> open my $fh, '<', $file or die "Cannot open $file: $!";
> my %seen;
> my @unique = grep {!$seen{$_}++} <$fh>;
^^^^^^^^^^
@unique disapears when the block ends (as does $fh and %seen.)
> }
>
> (Or, what does 'do' do here that I, too, should do 'do'?)
>
> Hmmmm, looking at my block, maybe the answer is "it places @unique outside
> of the block so that it is still accessible (but keeps our throwaway
> variables 'local')"?
Correct.
> BTW, doesn't 'sort -u' also sort the list?
No, the OP didn't want to sort the list, just find unique lines.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]