Perl

Author Message
mcds99

  • Total Posts : 519
  • Scores: 4
  • Reward points : 0
  • Joined: 2/28/2006
  • Status: offline
Perl Wednesday, June 04, 2008 9:05 AM (permalink)
0
I need to take a CSV file read a line, grap the first field (before the first comma, put that field in to a variable, create a file using that variable
Then I use a regx to parse the commas out of the line and write the file.
 
I did this
 open (sitcom, "sitcom.csv") || die "couldn't open the file!";
     while ($record = <sitcom>){
      $record =~ s/\,//ig;
         print $record;
     }
 close(sitcom);
 

It returns the rows from the file just fine.
Now I'm trying to read the row in to an array grab the first field and write the file.
 open (sitcom, "sitcom.csv") || die "couldn't open the file!";
     while ($record = <sitcom>){
      @Arry = $record;
         $fname = $Arry[0];
         open ($fname);
         close ($fname);
      $record =~ s/\,//ig;
         print $fname $record;
     }
 close(sitcom);
 close($fname);
 

 
Can someone point me in the right direction, I've been googleing and reading a book but my thick head just isn't gettint there...
 
Thanks
Sam.
Sam

Keep it Simple Make it Fun KiSMiF
 
#1
    mcds99

    • Total Posts : 519
    • Scores: 4
    • Reward points : 0
    • Joined: 2/28/2006
    • Status: offline
    RE: Perl Friday, June 06, 2008 7:54 AM (permalink)
    0
    So I figured it out ;-)
     open (sitcom, "sitcom.csv") || die "File Not Found!";   #Open file for read
         while ($record = <sitcom>){                                    #Loop
          @A = split(",",$record);                                           #Split data at the comma and load it in to an array "A"
          $L = $A[0];                                                               #Load each field in to a variable
          $M = $A[1];
          $N = $A[2];
          $O = $A[3];
          $P = $A[4];
          open wfile, ">>ARP$L.asc";                                     #Open a file for append using the first field as part of the name.
          
          print wfile $L," ";                                                        #Write the fields to the file
          print wfile $M," ";
          print wfile $N," ";
          print wfile $O," ";
          print wfile $P;
       print "\n";                                                                      #new line
         }
     close(sitcom);                                                                   #Close files
     close(wfile);
     

    Sam

    Keep it Simple Make it Fun KiSMiF
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9