I'm talking about using the split function to split the line into an array of fields, like this:
my $line = 'DATA/-/data123/data456//data789/-/AZ'; my @fields = split '/', $line;
that will put the fields in that array. Then you can check the first element of the array, $fields[0] , to see if it's in your hash of important keywords. If it is, you can grep the rest of the fields to see if any are the empty string or a dash. Here's an example with the sample line you gave:
#!/usr/bin/env perl use 5.010; use strict; use warnings; my %keys = ('DATA' => 1); # setup a hash of keywords my $line = 'DATA/-/data123/data456//data789/-/AZ'; my @fields = split '/', $line; # split line into fields on a slash if( $keys{$fields[0]} ){ # is the first element in my hash of +keywords my $keyword = shift @fields; # remove the keyword from the fields +array if( grep { $_ eq '' or $_ eq '-' } @fields ){ # are any elements + empty or a dash? say "Line has problems, keyword $keyword"; } }
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.
In reply to Re^3: Perl beginner here, needs a shove in the right direction.
by aaron_baugher
in thread Perl beginner here, needs a shove in the right direction.
by rfromp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |