Re: checking all pieces of split data for NULL

2004-08-13 Thread Jeff 'japhy' Pinyan
On Aug 10, Tim McGeary said:

Jeff 'japhy' Pinyan wrote:

   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.

You could use an array instead of a hash, then.  But the output isn't
unordered if you make @field_names hold the names in the order you want
them used.

-- 
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


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




Re: checking all pieces of split data for NULL

2004-08-13 Thread Tim McGeary
Jeff 'japhy' Pinyan wrote:
On Aug 10, Tim McGeary said:

Jeff 'japhy' Pinyan wrote:

 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.

You could use an array instead of a hash, then.  But the output isn't
unordered if you make @field_names hold the names in the order you want
them used.
How do I force that AND not output both parts of the hash since I just 
want the values, not the keys.


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



Re: checking all pieces of split data for NULL

2004-08-13 Thread Radhika Sambamurti
Hi,
Just for extra information, I am interested in understanding how the
if (grep length == 0, @arrayname) works.
Or perhaps I could be pointed to some documentation ie perldoc where i
could find out more about is it the length function? works.

thanks,
radhika


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


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




RE: checking all pieces of split data for NULL

2004-08-13 Thread Raymond Raj

 use perldoc -f length 


try perldoc perldoc how to use perldoc



-Original Message-
From: Radhika Sambamurti [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 11, 2004 11:16 PM
To: [EMAIL PROTECTED]
Subject: Re: checking all pieces of split data for NULL


Hi,
Just for extra information, I am interested in understanding how the
if (grep length == 0, @arrayname) works.
Or perhaps I could be pointed to some documentation ie perldoc where i
could find out more about is it the length function? works.

thanks,
radhika


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


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



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




Re: checking all pieces of split data for NULL

2004-08-10 Thread Tim McGeary
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



Re: checking all pieces of split data for NULL

2004-08-10 Thread Jeff 'japhy' Pinyan
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
  }

-- 
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


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




Re: checking all pieces of split data for NULL

2004-08-10 Thread Jose Alves de Castro
On Tue, 2004-08-10 at 15:01, Tim McGeary wrote:
 I have a file of data that I want to safety check to ensure that there 
 is data for each piece of the line being split.  Is there a fast way to 
 say If any of these are '' then write to error log?

Let's say you have your line split in @line

if (grep /^$/, @line) {

  # then one of them is null

}

 Thanks,
 Tim

HTH,

jac

 -- 
 Tim McGeary
 Senior Library Systems Specialist
 Lehigh University
 610-758-4998
 [EMAIL PROTECTED]
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


signature.asc
Description: This is a digitally signed message part


Re: checking all pieces of split data for NULL

2004-08-10 Thread Wiggins d Anconia
 I have a file of data that I want to safety check to ensure that there 
 is data for each piece of the line being split.  Is there a fast way to 
 say If any of these are '' then write to error log?
 
 Thanks,
 Tim
 

Do you mean something like?

foreach my $piece (split /\|/, $line) {
   if ($piece eq '') {
   print ERRORLOG Empty value;
   }
}
(Assumes split on '|' but doesn't have to)

Obviously this is not terribly useful as it doesn't tell you what was
empty, but there are lots of ways around that, obviously you will need
to know the column headings.

Does this help?  If not you might provide more information specifically
about what you are up to.

http://danconia.org

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




RE: checking all pieces of split data for NULL

2004-08-10 Thread Moon, John
-Original Message-
From: Tim McGeary [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 10, 2004 10:01 AM
To: [EMAIL PROTECTED]
Subject: checking all pieces of split data for NULL

I have a file of data that I want to safety check to ensure that there 
is data for each piece of the line being split.  Is there a fast way to 
say If any of these are '' then write to error log?

Thanks,
Tim


Assuming the you wish to split on a comma 
then:

print Bad data $data\n if $data =~ /,\s*,/ || $d =~ /,\s*$/;

hope this gives you some ideas...

jwm

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




Re: checking all pieces of split data for NULL

2004-08-10 Thread JupiterHost.Net

Tim McGeary wrote:
I have a file of data that I want to safety check to ensure that there 
is data for each piece of the line being split.  Is there a fast way to 
say If any of these are '' then write to error log?
How about this:
for(@lines) {
  chomp;
  print ERRLOG 'Blank line' if $_ eq '';
  # where ERRLOG is a previously opened file handle
  # you could do if !$_; but that would also match '0'
}
HTH :)
Lee.M - JupiterHost.Net
Thanks,
Tim
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: checking all pieces of split data for NULL

2004-08-10 Thread Tim McGeary
this didn't go through the first time...  resending...
Jeff 'japhy' Pinyan wrote:
On Aug 10, Tim McGeary said:

I have a file of data that I want to safety check to ensure that there
is data for each piece of the line being split.  Is there a fast way to
say If any of these are '' then write to error log?

Assuming you store the data in an array, you can simply say:
  if (grep length == 0, @data_members) {
print LOG error: empty fields found in this dataset\n;
  }
Something to that effect should work.
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.
Does that change the scope of this suggestion?


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



Re: checking all pieces of split data for NULL

2004-08-10 Thread Tim McGeary
Tim McGeary
Senior Library Systems Specialist
Lehigh University
610-758-4998
[EMAIL PROTECTED]

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
  }

since I have this already:
foreach $item (@banner_array) {
my ($patron_id, $name_f, $name_l, $email, $disc_id, $contact,
$pwd, $un, $group, $code) = split(/,/,$item);
can I just simply do:
if ($patron_id | $name_f | $name_l | ... eq '') {
send to error log
???
| = OR, but maybe I'm not correct with that.
Tim

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



RE: checking all pieces of split data for NULL

2004-08-10 Thread Bob Showalter
Tim McGeary wrote:
 I have a file of data that I want to safety check to ensure that there
 is data for each piece of the line being split.  Is there a fast way
 to say If any of these are '' then write to error log?

   die One or more fields is zero length\n if grep !length, @fields;

   die One or more fields is all whitespace\n if grep $_ !~ /\S/, @fields;

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




Re: checking all pieces of split data for NULL

2004-08-10 Thread Tim McGeary

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

I have a file of data that I want to safety check to ensure that there
is data for each piece of the line being split.  Is there a fast way to
say If any of these are '' then write to error log?

Assuming you store the data in an array, you can simply say:
  if (grep length == 0, @data_members) {
print LOG error: empty fields found in this dataset\n;
  }
Something to that effect should work.
Yes, they are indeed in an array.  Excellent.  I'll try this out.  Thank 
you.

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



Re: checking all pieces of split data for NULL

2004-08-10 Thread Jeff 'japhy' Pinyan
On Aug 10, Tim McGeary said:

I have a file of data that I want to safety check to ensure that there
is data for each piece of the line being split.  Is there a fast way to
say If any of these are '' then write to error log?

Assuming you store the data in an array, you can simply say:

  if (grep length == 0, @data_members) {
print LOG error: empty fields found in this dataset\n;
  }

Something to that effect should work.

-- 
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


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




Re: checking all pieces of split data for NULL

2004-08-10 Thread Tim McGeary
Jeff 'japhy' Pinyan wrote:
On Aug 10, Tim McGeary said:

I have a file of data that I want to safety check to ensure that there
is data for each piece of the line being split.  Is there a fast way to
say If any of these are '' then write to error log?

Assuming you store the data in an array, you can simply say:
  if (grep length == 0, @data_members) {
print LOG error: empty fields found in this dataset\n;
  }
Something to that effect should work.
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.

Does that change the scope of this suggestion?

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



Re: checking all pieces of split data for NULL

2004-08-10 Thread Jeff 'japhy' Pinyan
On Aug 10, Tim McGeary said:

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

How do I force that AND not output both parts of the hash since I just
want the values, not the keys.

What do you mean, both parts of the hash?  My empty_fields() function
only displays the long names of the fields.

-- 
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


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