Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: can't use unpack or split??

by eclark (Scribe)
on Jun 07, 2004 at 19:46 UTC ( #362086=note: print w/replies, xml ) Need Help??

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?


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://362086]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2022-05-24 11:28 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.