http://qs321.pair.com?node_id=362086


in reply to can't use unpack or split??

How about this?

open FH, "<datafile"; while (my $line = <FH>) { chomp $line; my @a = ($line =~ /('{1}.*?'{1}(?=\s+)|\S+)/g); print join('|', @a) . "\n"; } close FH;

Replies are listed 'Best First'.
Re^2: can't use unpack or split??
by seaver (Pilgrim) on Jun 07, 2004 at 20:12 UTC
    Thanks for your reply, it totally makes sense, however I wasn't explicit enough in my question.

    You've coded the search pattern specifically for the example I gave above, but truly, the 4 or 5 characters in the second column could be ANY character, and not necessarily be delimited by ' as they are in the example above.

    After having thought about this, the two things I can guarantee are:

    1. The first three characters are FIXED.

    2. There is a space between every column

    3. The second column is at least 1 character, and at the most 5 characters

    So my problem is truly that I have columns delimited by spaces, (nothing I can do about that) and the second column may actually have within it, a space...!!

    Any more ideas?

    Cheers
    Sam