Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Reading a CSV File and outputting a text file


    I am reading a csv formatted file and outputting it into a text file using Perl 5.6
    For the life of me I cannot figure out what I am doing wrong. I had an example to work from but the example didn't work and I just don't have enough Perl knowledge to troubleshoot it further.
    Code:
    format HRSDLABEL = 
     Status  Brand  Availability_Date  Discontinue_Date  Change_Date  SKU  Product_Name  Language  Previous_SKU  Program  Reseller_Cost  Suggested_List_Price  Points  UPC_Code  Weights  Dimensions  Units  Media  ECCN  Null  Category  
    {"@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<","@<<<<<<<<<<<<<<<<<<<<<<<<<<"}
    $Status,$Brand,$Availability_Date,$Discontinue_Date,$Change_Date,$SKU,$Product_Name,$Language,$Previous_SKU,$Program,$Reseller_Cost,$Suggested_List_Price,$Points,$UPC_Code,$Weights,$Dimensions,$Units,$Media,$ECCN,$Null,$Category
    .
    
    $prodnameandsku=$Product_Name . '-' . $SKU;
    open( HRSDLABEL, "> products.csv" ) || die "can't create";
    open( Employees_HRSD, " format.txt" ) || die "cannot open HRSDs File";
    while ( <Employees_HRSD> ) {
        chomp; # remove newline
    ($prodnameandsku,'cabox.gif',$prodnameandsku,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,'date','-1','1',$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Category,$Null,$Null,'--none--','Active','EOREOR') = split(/,/);
    write (HRSDLABEL); # send the output
    }
    When it is run I get the error:
    Can't modify constant item in list assignment at osc.pl line 12, near ");"
    Execution of osc.pl aborted due to compilation errors.

    Any help greatly appreciated!

  2. #2
    -->
    i think its with your "split" statement
    Code:
    ....
    ($prodnameandsku,'cabox.gif',$prodnameandsku,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,'date','-1','1',$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$Category,$Null,$Null,'--none--','Active','EOREOR') = split(/,/);
    ...
    The error says there cannot be constant at left hand side of splot. maybe you want to change it to $gif
    then assign "cabox.gif" to $gif?...same with the last few ..like 'Active' and so on..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •