Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found