[Chicago-talk] Problems with split (removing trailing fields)

Jay Strauss me at heyjay.com
Tue Feb 24 13:24:48 CST 2004


Hi,  I'm trying to parse a data stream whose delimiter is a chr(0).  The
problem is split " By default, empty leading fields are preserved, and empty
trailing ones are deleted."  Basically, I'm loosing data that I need.

1) can I change splits default behavior?  (it doesn't mention it in the
perldoc)
2) can someone show me a regex that would split the data into the proper
fields?

# below is an example of what is happening.  Specifically, I'm loosing the
final <null> field.

sub get_one {

        my $self = shift;
        $self->[FRAMING_BUFFER] =~ s/$self->[DELIMITER]/\|/g;

        print "B:", $self->[FRAMING_BUFFER],"\n";
        my @a = split /\|/, $self->[FRAMING_BUFFER];
        print "A:", join("|", @a),"\n";
}

B:1|2|404|1||1|2|404|2||1|2|404|4||2|2|404|0|0|2|2|404|3|0|2|2|404|5|0|1|2|4
04|6||1|2|404|7||2|2|404|8|0|1|2|404|9||
A:1|2|404|1||1|2|404|2||1|2|404|4||2|2|404|0|0|2|2|404|3|0|2|2|404|5|0|1|2|4
04|6||1|2|404|7||2|2|404|8|0|1|2|404|9

Thanks
Jay




More information about the Chicago-talk mailing list