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

  • SEARCH
  • Home
  • 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 8507059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:45:45+00:00 2026-06-11T02:45:45+00:00

I am just trying to read .csv file first time.I have gone through the

  • 0

I am just trying to read .csv file first time.I have gone through the below link :

http://metacpan.org/pod/Text::CSV_XS#Reading-a-CSV-file-line-by-line:

I have few doubt, well if you want, u can tell me this are silly question but i don’t know, why i am not able to figure it out that how exactly perl is reading csv file 🙁

So, my doubt is:

First Question

What is the difference between reading the csv file line by line and parsing the file.

I have simple program where i am reading the csv file line by line.
Below is my program:

#!/usr/bin/perl -w
use strict;
use Text::CSV;
use Data::Dumper;

my $csv=Text::CSV->new( );
my $my_file="test.csv";
open(my $fl,"<",$my_file) or die"can not open the file $!";
#print "$ref_list\n";

while(my $ref_list=$csv->getline($fl))
{
 
print "$ref_list->[0]\n";
} 

Below is the data in csv file :

"Emp_id","Emp_name","Location","Company"
102713,"raj","Banglore","abc"
403891,"Rakesh","Pune","Infy"
530201,"Kiran","Hyd","TCS"
503110,"raj","Noida","HCL"

Second Question:

If I want to get specific Emp_id along with Location then how can i proceed.

Third Question :

If I want only 102713 ,530201,503110 Emp record i.e name,location,compnay name then what should i do ?

Thanks

  • 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-06-11T02:45:46+00:00Added an answer on June 11, 2026 at 2:45 am

    A CSV file is a good representation of tabular data in a text format, but it is unsuitable for an in-memory represenation. Because of that, we have to create an adequate representation. One such representation would be a hash:

    my $hashref = {
       Emp_Id   => ...,
       Emp_name => ...,
       Location => ...,
       Company  => ...,
    };
    

    If the header row is in the array @header, we can create this hash with:

    my @header = ...;
    my @row = @{$csv->getline($fl)}; # turn the arrayref into an array
    my $hashref = {};
    for my $i (0..$#header) {
      $hashref->{$header[$i]} = $row[$i];
    }
    # The $hashref now looks as described above
    

    We can then create lookup hashes that use the id values as keys. So %lookup looks like this:

    my %lookup = (
       102713 => $hashref_to_first_line,
       ...,
    );
    

    We populate it by doing

    $lookup{$row[0]} = $hashref;
    

    after the above loop. We can then access a certain hashref with

    my $a_certain_id_hashref = $lookup{102713};
    

    or access certain elements directly with

    my $a_certain_id_location = $lookup{102713}{Location};
    

    If the key does not exist, these lookups should return undef.

    If the CSV file is too big, this might cause perl to run out of memory. In that case, the hashes should be tied to files, but that is a different topic completely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to split just a string I've read in through a csv
I am trying to read a file using csv.DictReader I have a field that
I'm just trying to do a simple text file read in java for my
To simplify, I'm trying to read the content of a CSV-file using the ifstream
I am just trying to read some details from an XML file, part of
its my first time to access and read an excel file (xlsx) with c#..
I'm trying to read data from a.csv file to ouput it on a webpage
I am just trying to read each character of the file and print it
I am trying to read from csv file. The file contains UTF-8 characters. So
I'm trying to read a CSV file with a date format 06/01/05 (month/date/year) into

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.