Re: Help with script
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Thu, 28 Feb 2008 19:26:39 GMT
Andy wrote:
On Feb 28, 1:15 pm, "John W. Krahn" <some...@xxxxxxxxxxx> wrote:Andy wrote:
I am pretty new here, tyring to learn as I go.while ( <FH> ) {
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 ?
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
Thank you Very Much
I take it I have to turn around and
Add
!#/usr/bin/perl -w
Better to add:
#!/usr/bin/perl
use warnings;
use strict;
Question How does the script know that I want it to Scrub a particular
file.
It doesn't. The example posted is incomplete.
In this case the Above snippet is from a file called
msus.dat
Open the file first:
open FH, '<', 'msus.dat' or die "Cannot open 'msus.dat' $!";
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
.
- References:
- Help with script
- From: Andy
- Re: Help with script
- From: John W. Krahn
- Re: Help with script
- From: Andy
- Help with script
- Prev by Date: Re: Help with script
- Next by Date: Re: code help
- Previous by thread: Re: Help with script
- Next by thread: Re: Help with script
- Index(es):
Relevant Pages
|
|