in reply to Re: Perl beginner here, needs a shove in the right direction.
in thread Perl beginner here, needs a shove in the right direction.

Thank you Aaron B, design is one of my weaknesses. You specifically say to "split the line into fields", however the lines are already delimited into fields by a forward slash, so is there something extra needed there?

The line of the file I'm interested in looks something like this:

DATA/-/data123/data456//data789/-/AZ

Replies are listed 'Best First'.
Re^3: Perl beginner here, needs a shove in the right direction.
by aaron_baugher (Curate) on Jun 17, 2015 at 01:11 UTC

    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.