Member Avatar for perlguy

I am trying to modify a parser for delimited files I already wrote so it works on a delimited file that doesn't contain each set of data on the same line. So for example,

||A||B||C||D||E||F
||G||H|||A||B||C||
D||E||F||G||H|||A

where each data set is separated by 3 pipes instead of 2. Can anyone give me some pointers?

Recommended Answers

All 3 Replies

if the file isn't too big this might do what you want:

open(FH,'file.txt');
my $data = do {local $/; <FH>};
my @data = split(/\|\|\|/,$data);
print "$_\n" for @data;
Member Avatar for perlguy

thanks for the reply, one more question, after grabbing each data set I need to parse out each data field. This doesn't seem to be working:

while(<FILE>){
        my $data = do {local $/; <FILE>};
        my @data = split(/\|\|\|/,$data);

    }

    my @values = split(/\|\|/,$data);
my @data = ();
    my @values = ();
    while(<FILE>){
        my $data = do {local $/; <FILE>};
        @data = split(/\|\|\|/,$data);
 
    }
     
    for (@data) {
       @values = split(/\|\|/);
       #do something with @values
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.