in reply to split a delimited file

Are the fields for each comment separated by "\t::\t" or are the separate comment entries (with 10 fields each) separated by "\t::\t" with individual fields separate by "\n::\n" or something else(as code #2 semi-suggests)?

If 2, use local $/ = "\t::\t"; to read in entries at a time, and split the fields from there.



Code is (almost) always untested.
http://www.justicepoetic.net/

Replies are listed 'Best First'.
Re: Re: split a delimited file
by JayBee (Scribe) on Feb 08, 2004 at 03:14 UTC
    Your second assumption is correct. I just looked up local, but I am not familiar with "$/". What does it do/mean? and where do I use it, within a {while (<open>)} statement, before/after the open (FILE, '$file') line? or do you mean to put my ($item1, $item2, $item3) in place of the "$/" ? Thaks for your help
      Start your program with
      local $/ = "\t::\t";
      Then, when you use <FH>, it won't give you the next line but the next record, that us, up to the next occurance of "/t::/t". Then, within your while loop, your $_ is now something like (if "\n::\n" is the field separator)
      uname :: categ :: title :: locat :: $desc etc.
      Then, just split that bad boy into individual fields like you do in your second code sample and you'll be set.

      HTH.



      Code is (almost) always untested.
      http://www.justicepoetic.net/
      You can read about $/ and its effect on the readline (aka <>) operator in perldoc perlvar.