in reply to Re: split problem...
in thread split problem...

He/she has multiple lines in a single database field; I don't see how your code applies to this situation.

I actually thought the:

while ($input) { ($field, $input) = split /delim/, $input, 2; # process $field }
was a very interesting idiom, and one I hadn't seen before.

Replies are listed 'Best First'.
Re^3: split problem...
by tachyon (Chancellor) on Sep 27, 2004 at 06:59 UTC

    Perhaps I should have read a little closer, although the cause of his issue is not immediately evident. I agree it is an unusual idiom. While the use in the loop could be rationalised the use in the two splits on ^ seems pretty dubious at first glance. This would be pretty usual sort of syntax assuming the data is in blocks as you suggest.

    local $/ = ""; # set paragraph mode to read one record at a time while (my $record = <DATA>) { for ( split /[\n\r]+/, $record ) { my ($Num, $Qt, $_trashit) = split /\^/, $_; print "$Num || $Qt || $_trashit\n"; } } __DATA__ 22009^1^52.90 22010^1^42.90 22011^1^32.90 22009^1^52.90 22010^1^42.90 22011^1^32.90

    cheers

    tachyon