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 8471977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:56:32+00:00 2026-06-10T16:56:32+00:00

am very new to Perl and need your help I have a CSV file

  • 0

am very new to Perl and need your help

I have a CSV file xyz.csv with contents:

here level1 and er values are strings names…not numbers…

level1,er
level2,er2
level3,er3
level4,er4

I parse this CSV file using the script below and pass the fields to an array in the first run

open(my $d, '<', $file) or die "Could not open '$file' $!\n";
while (my $line = <$d>) {
  chomp $line; 
  my @data = split "," , $line; 
  @XYX = ( [ "$data[0]", "$data[1]" ], );
}

For the second run I take an input from a command prompt and store in variable $val. My program should parse the CSV file from the value stored in variable until it reaches the end of the file

For example

I input level2 so I need a script to parse from the second line to the end of the CSV file, ignoring the values before level2 in the file, and pass these values (level2 to level4) to the @XYX = (["$data[1]","$data[1]"],);}

level2,er2
level3,er3
level4,er4

I input level3 so I need a script to parse from the third line to the end of the CSV file, ignoring the values before level3 in the file, and pass these values (level3 and level4) to the @XYX = (["$data[0]","$data[1]"],);}

level3,er3
level4,er4

How do I achieve that? Please do give your valuable suggestions. I appreciate your help

  • 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-10T16:56:34+00:00Added an answer on June 10, 2026 at 4:56 pm
    #!/usr/bin/perl  
    use strict;     
    use warnings;
    open(my $data, '<', $file) or die "Could not open '$file' $!\n"; 
    my $level = shift ||"level1"; 
    while (my $line = <$data>) {  
    chomp $line; 
    my @fields = split "," , $line; 
    if($fields[0] eq $level .. 0){
    print "\n$fields[0]\n";
    print "$fields[1]\n";
    }}
    

    This worked….thanks ALL for your help…

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

Sidebar

Related Questions

I am very new to Perl, so please bear with my simple question: Here
I very new to Python, and fairly new to regex. (I have no Perl
Pretty new to Perl so there may be a very obvious solution here. I'm
I'm new to Perl and I really need help witch a specific issue. I
Apologies for a simple question, but I'm very new to Perl! I have an
I have the following code in Perl. I am very new to the language:
I have very little Perl experience. I need to read a binary image in
I'm very new to Perl, and I have absolutely no idea how to approach
I have a simple log file which is very messy and I need it
I have a very common situation. I have a file, and I need to

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.