On Jan 20, 7:20*am, Tad J McClellan <ta...@seesig.invalid> wrote:
> Larry Gates <la...@example.invalid> wrote:
> > The first thing I'll want to do is capture the first seven characters in a
> > line. *
>
> * * my $first7 = substr $line, 0, 7;
>
> > We can assume that these will always be letters or spaces padded out
> > to the right.
>
> If you want to validate the data against those criteria, then:
>
> * * die "'$first7' is 'bad' data\n" unless $first7 =~ /^[a-z]+\s*$/i;
>
> > After that, I want to strip away all the characters,
>
> Errr... OK:
>
> * * $first7 = '';
>
> If you instead meant to say "strip away all the trailing space characters":
>
> * * $first7 =~ s/\s+$//;
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Maybe you meant 'strip away all of the non numeric characters'.
$first7 =~ s/\D//g;
That will also take out any periods and negative signs which you might
want so you might have to tailor the expression a bit more than that.
Perhaps you could split the lines of the input file into fields and
then write some conditional logic which might do different
substitutions based on what expression the data matches before you
populate your objects.
$field =~ s/\s//g;
if ( $field =~ /\d+\./ ) {
...
} elsif { $field =~ /^*\d+\D/ ) {
etc...
}
A really "great way to continue exploring perl's pattern-matching
capabilities" might be to go to
http://www.perl.com/doc/manual/html/pod/perlre.html
or type
perldoc perlre <enter>
or read your textbook more closely maybe?
Good luck,
Trey