Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello everyone
I have a weird problem... I have a CSV file. I would usually load up the file and parse it line by line, but for some reason all the lines appear to be stuck together, so it is one long string of concatinated rows. I presume this is because there are no line breaks? But when I load the file up in my text editor it shows the file as you would expect, with each row on a new line. So i'm a bit confused.

Here is an example of the code I am using:

open FH, "< $csv_file" or die "$!"; foreach my $offer (<FH>) { print "$offer\n"; my @fields = split(',',$offer); } close(FH) or die "$!";

And here are the first few rows of the CSV file:

producttype,price,imageurl,itemname,description,ctpage,smallimageurl,t +opseller,tagline Lifestyle,19.9899997711,http://images.iwoot.com/medium/globri_med.jpg, +Glow Brick,This light leads an exotic double life. By day it's a quie +t mild-mannered acrylic brick; by night it's a show-stopping illumin +ation that lights up as darkness falls...,http://www.dgm2.com/m/iwant +o/b.asp?a=1081&i=14497&c=http://www.iwantoneofthose.com/GLOBRI.htm,ht +tp://images.iwoot.com/thumbs/globri_thu.jpg,0, Toys & Games,11.9899997711,http://images.iwoot.com/medium/glofri_med.g +if,Glow in the dark frisbee,The 175g Discraft Ultra-Star is the offic +ial disc of the Ultimate Players Association - but who cares it's a +Frisbee that glows in the dark so it's a blast in the park!,http://ww +w.dgm2.com/m/iwanto/b.asp?a=1081&i=14497&c=http://www.iwantoneofthose +.com/GLOFRI.htm,http://images.iwoot.com/thumbs/glofri_thu.gif,0, Toys & Games,24.9899997711,http://images.iwoot.com/medium/glx200_med.g +if,AIR ROCKET - GLX-200,The GL-X200 Rocket Launcher powers rockets up + to 250 feet into the air.,http://www.dgm2.com/m/iwanto/b.asp?a=1081& +i=14497&c=http://www.iwantoneofthose.com/GLX200.htm,http://images.iwo +ot.com/thumbs/glx200_thu.jpg,0, Electronics,54.9900016785,http://images.iwoot.com/medium/surhea_med.jp +g,5.1 Surround Sound Headset,Imagine a five speaker surround-sound sy +stem buried in your head without the medical complications and you' +re getting close to the experience of wearing this awesome set of hea +dphones.,http://www.dgm2.com/m/iwanto/b.asp?a=1081&i=14497&c=http://w +ww.iwantoneofthose.com/HEASET.htm,http://images.iwoot.com/thumbs/surh +ea_thu.jpg,0,

Any ideas how I can parse the file?

Thanks, Tom


In reply to Parsing a text file without newlines by existem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-25 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found