Jeff 'japhy' Pinyan wrote:
On Aug 10, Tim McGeary said:


follow-up question:  will this only be true if $item of @array is
completely empty?  This is the type of data for each $item of @array:

ID, name_f, name_l, email, id, contact, group, member

I am splitting this by commas into different $scalers to manipulate.
And I know that same of these fields are empty (to which I need to
report back to the people sending me the data).  It will NEVER happen
that a whole line is empty, but just one or two of the fields in each line.


I don't see how this changes things, really.  This is how I would do
things:

  my @field_names = qw( ID name_f name_l email id contact group member );
  my %long_names;
  @[EMAIL PROTECTED] = (
    'ID', 'First Name', 'Last Name',
    'Email Address', 'id', 'Contact', 'Group', 'Member',
  );

  while (<INPUT>) {
    chomp;
    my %record;
    @[EMAIL PROTECTED] = split /,/;
    if (my @empty = grep length $record{$_} == 0, @field_names) {
      empty_fields(@empty);
    }
    else {
      # process record
    }
  }

Where the empty_fields() function would do something like:

  sub empty_fields {
    my $msg = "You left these fields empty: ";
    $msg .= join ", ", @[EMAIL PROTECTED];
    # displays $msg to the user somehow
  }


This makes my output unordered and extraneous. I don't want to field_names to output, so I don't think a hash works for this. But in its essense, it is what I need to do. I just need to keep the field_names from outputting, too. Just the data, in the same order I bring it in.


Tim


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to