Here is the standard approach:
(1) In file X/CCD/Human.pm (where X is some directory listed in @INC):
package CCD::Human; use strict; use warnings; sub new { my ($class, $in_filename, $out_filename) = @_; my %self = ( in => $in_filename, out => $out_filename, ); return bless \%self, $class; } sub parse { my ($self) = @_; open(my $in, '<', $self->{in}) or die "Cannot open file '$self->{in}' for reading: $!"; open(my $out, '>', $self->{out}) or die "Cannot open file '$self->{out}' for writing: $!"; while (<$in>) { chomp; my @fields = split /\t/; print $out "$fields[0] $fields[2] $fields[6] $fields[ +5]\n" if ($fields[0] =~ /16/ && $fields[6] eq '-' && $fields[5] =~ /Public/); } close $in or die "Cannot close file '$self->{in}': $!"; close $out or die "Cannot close file '$self->{out}': $!"; }
(2) Client code would use this class as follows:
use CCD::Human; ... my $human = CCD::Human->new ( '/home/ki/Downloads/currenthumanccds.txt', '/home/ki/output.txt', ); ... $human->parse();
Disclaimers:
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^3: creating a class with encapsulation ?
by Athanasius
in thread creating a class with encapsulation ?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |