troubleshooting Question

Perl script to generate a CSV file

Avatar of itsme_asif
itsme_asif asked on
Shell ScriptingPerl
9 Comments1 Solution1042 ViewsLast Modified:
This is the script i have
Instead of getting the output as

20,,,,,abc,0,,,reportingHirarchy,,,
21,,,,,cfg,0,,,21,,,
22,,,,,ijk,0,,,22,,,
23,,,,,asd,0,,,23,,,
24,,,,,asj,0,,,24,,,
25,,,,,qwe,0,,,25,,,

I am getting as

30,,,,,abc,0,,,reportingHirarchy,,,
30,,,,,cfg,0,,,21,,,
30,,,,,ijk,0,,,22,,,
30,,,,,asd,0,,,23,,,
30,,,,,asj,0,,,24,,,
30,,,,,qwe,0,,,25,,,

can you please help!
#!/usr/bin/perl
 
#use strict;
#use warnings;
 
open my $CSV, '<', 'sample1.csv' or die "failed to open 'sample1.csv' $!";
open my $TXT, '<', 'sample.txt' or die "failed to open 'sample.txt' $!";
open my $NEW, '>', 'new1.csv' or die "failed to open 'new1.csv' $!";
 
 
 
while(<$CSV>) {
   chomp;
   my @csv = split /,/;
  for ($i=20;$i<=30;$i++) {
 
   $csv[0]=$i;
}
   my $phone = <$TXT>;
   chomp $phone;
   $csv[5] = $phone;
   no warnings;         
  $i=$i+1; 
  print $NEW join(',', @csv[0..12]) . "\n";
   
   use warnings;
}
ASKER CERTIFIED SOLUTION
marchent

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros