Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help prccessing a flat-file

Status
Not open for further replies.

leegold

Technical User
Mar 19, 2002
39
US
Say I have records like:

_aaa###_bbb###_ccc###_ddd

I want all records to be prcessed to:

_aaa###_bbb_ccc_ddd

so that only the 1st '###' separator is kept, the rest are deleted. I could split and join...and when I join do "something" - but what? Thanks.
while (<INFILE>) {
chomp;
$zapvar = $_;
@fields= split(/###/, $zapvar);
$zapvar = join('###', @fields); # WHAT DO I DO?
print OUTFILE "$zapvar\n";
}
 
while (<INFILE>) {
~s/###//g;
~s/(_.*?)_/$1###_/;
print OUTFILE "$_";
}
 
not sure I quite understand?

[tt]#!/usr/bin/perl

while (<DATA>) {
($a,$b,$c,$d) = split("###");
print "$a###$b$c$d";
}

__DATA__
_aaa###_bbb###_ccc###_ddd
_eee###_fff###_ggg###_hhh
_www###_xxx###_yyy###_zzz[/tt]


outputs:-

[red][tt]_aaa###_bbb_ccc_ddd
_eee###_fff_ggg_hhh
_www###_xxx_yyy_zzz[/tt][/red]


Kind Regards
Duncan
 
could records

".. like:

_aaa###_bbb###_ccc###_ddd"

include:
_aaa###_bbb###_ccc###_ddd###_eee
or
_aaa###_bbb###_ccc

isn't a general algorithm preferable?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top