Re: Help with script
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Thu, 28 Feb 2008 18:15:30 GMT
Andy wrote:
I am pretty new here, tyring to learn as I go.
I have a lil project I am trying to setup
Basically : below is a piece of the file
Has three fields Seperated by ~
6081703039~1~My Own Company
3081709039~1~DeweyCheetham&Howe
9081710039~1~One Bad Firm
2081757039~1~IRSUSUCK
1082445039~1~
Basically I need the file to only show the Field that has all data
I am new so not sure if my syntax is correct
If field 3 is blank then don't show?
Can anyone help me write a Perl script to acocmplish this ?
while ( <FH> ) {
chomp;
my @fields = split /~/, $_, -1;
if ( 3 != @fields ) {
warn "Error: should be 3 fields, record contains " . @fields . " fields instead.\n";
next;
}
if ( 3 != grep length, @fields ) {
warn "Error: one of the fields is empty.\n";
next;
}
# Or, just the third field:
unless ( length $fields[ 2 ] ) {
warn "Error: the third field is empty.\n";
next;
}
# process the data
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- Follow-Ups:
- Re: Help with script
- From: Andy
- Re: Help with script
- References:
- Help with script
- From: Andy
- Help with script
- Prev by Date: Re: Help with script
- Next by Date: Re: Generate an associative array from a file
- Previous by thread: Re: Help with script
- Next by thread: Re: Help with script
- Index(es):
Relevant Pages
|
|