Advertisement

07.22.2008 at 11:11AM PDT, ID: 23585993
[x]
Attachment Details

Perl script to generate a CSV file

Asked by itsme_asif in Perl Programming Language, KornShell (ksh)

Tags: Perl

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!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
#!/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;
}
[+][-]07.22.2008 at 12:42PM PDT, ID: 22062906

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 12:44PM PDT, ID: 22062925

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 12:53PM PDT, ID: 22063000

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 01:32PM PDT, ID: 22063376

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Perl Programming Language, KornShell (ksh)
Tags: Perl
Sign Up Now!
Solution Provided By: marchent
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07.22.2008 at 01:34PM PDT, ID: 22063386

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 01:34PM PDT, ID: 22063387

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 01:54PM PDT, ID: 22063578

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 02:53PM PDT, ID: 22064057

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 03:25PM PDT, ID: 22064268

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628