in reply to split problem...

You are making an easy task look hard. It isn't. Try this:

while(<DATA>) { s/\s+$//; # trim off any \015 chars on EOL my ($Num, $Qt, $_trashit) = split /\^/, $_; print "$Num || $Qt || $_trashit\n"; # blah } __DATA__ 22009^1^52.90 22010^1^42.90 22011^1^32.90

Just replace DATA with the database filehandle.

Now the split on ^ will work so if it *apparently does not* it is because your data is not what you think it is. Your debugging code is not adequate as you want to really want to look at the data you are trying to process (ie the line) as well. You can save typing effort simply by using warn ie warn "Got ($line)\n". If you want it in a file just do ./script.pl 2>debug.log to redirect STDERR to a file.

cheers

tachyon

Replies are listed 'Best First'.
Re^2: split problem...
by ysth (Canon) on Sep 27, 2004 at 06:50 UTC
    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.

      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