Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3395692
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:19:08+00:00 2026-05-18T04:19:08+00:00

Decided to try and learn Perl, and currently need to process a number of

  • 0

Decided to try and learn Perl, and currently need to process a number of CSV files.

To get started doing more advance text manipulation I first need a base code that:

  • Imports a local CSV
  • Does a basic text manipulation
  • Save the resulting changed values

The import/process/export should support 1000+ rows and 20+ columns. Going to supplies a sample CSV file, but feel free to supply one in your answer.

SAMPLE CSV FILE:

"EmployeeName","OfficeHistory","JobLevelHistory"
"John Smith",501,"Engineer"
"John Smith",601,"Senior Engineer"
"John Smith",701,"Manager"
"Alex Button",601,"Senior Assistant"
"Alex Button",454,"Manager"

If you have any questions, let me know — this will be a HUGE help in me getting started. My main focus is the text manipulation, but the manipulations are meaningless unless I’ve got a way to input data and export it back to a file. Also, if you have any suggestion for quickly creating and debugging text manipulations that would be a huge help too. (NOTE: Currently use an application to do this, but need more control, and decided to give Perl a try.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:19:08+00:00Added an answer on May 18, 2026 at 4:19 am

    Use Text::CSV_XS or Text::CSV.

    Anything else will drive you insane, sooner or later. CSV is an unruly format in practice, though there are rules laid down (RFC 4180) but they were defined somewhat post hoc so some systems, notably by Microsoft, handle them differently. MS did indeed get there first, but there are differences between the CSV formats recognized by different MS products.


    Rehash of Text::CSV manual page

    #!/usr/bin/env perl
    use strict;
    use warnings;
    use Text::CSV;
    
    my @rows;
    
    # Read the CSV file
    {
        my $csv = Text::CSV->new()
            or die "Cannot use Text::CSV ($!)";
        my $file = "data.csv";
        open my $fh, '<', $file
            or die "Cannot open $file ($!)";
    
        while (my $row = $csv->getline($fh))
        {
            push @rows, $row;
        }
        $csv->eof or $csv->error_diag();
    
        close $fh
            or die "Failed to close $file ($!)";
    }
    
    # Munge the data
    {
        foreach my $row (@rows)
        {
            foreach my $col (@{$row})
            {
                $col = uc($col);
            }
            print "\n";
        }
    }
    
    # Write the data
    {
        my $csv = Text::CSV->new()
            or die "Cannot use Text::CSV ($!)";
        my $file = "output.csv";
        open my $fh, '>', $file
            or die "Cannot open $file ($!)";
        $csv->eol("\n");
        foreach my $row (@rows)
        {
    
            $csv->print($fh, \@{$row})
                or die "Failed to write $file ($!)";
        }
        close $fh
            or die "Failed to close $file ($!)";
    }
    

    Output based on your sample data

    EMPLOYEENAME,OFFICEHISTORY,JOBLEVELHISTORY
    "JOHN SMITH",501,ENGINEER
    "JOHN SMITH",601,"SENIOR ENGINEER"
    "JOHN SMITH",701,MANAGER
    "ALEX BUTTON",601,"SENIOR ASSISTANT"
    "ALEX BUTTON",454,MANAGER
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, I'm basically new to programming. I've decided to try and get started
I recently decided to try to learn some bash scripting and as a fun
I've started working on my master's project and decided to try something new and
So a few days ago I decided I would try and learn Ruby and
I started doing Project Euler and got to problem number 9 . Since I
I decided to try http://www.screwturn.eu/ wiki as a code snippet storage utility. So far
So I've decided to try to solve my physics homework by writing some python
Following the advice of wcoenen, I've decided to try using registration-free COM. This works
I decided to learn C++ (I program in C at work), and I have
I decided that I was ready to try something new, after a few years

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.