Training, Open Source
computer languages


PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Adding comma(,) after every number+ perl

Posted by ksamir2004 (ksamir2004), 15 May 2008
Hello All,

i am new member of this forum. can any one help me for adding comma(,). after every number.
i have excel file. in that file there is more then 100 number in single row seperated by column . i want perl script which read form excel and add comma (,).

example : 11226 11342219 11990841 12001109 12006533

Solution: 11226,11342219,11990841,12001109,12006533

---------------------------------------------
  open MARGIN, &#8220;<x.csv&#8221; or die &#8220;open x.csv: $!&#8221;;
     while (<MARGIN>) {
     chop;
     (@content) = split /,/;
     $prod_margin{$content[1]} = @content;
     }
     close MARGIN;
     open MARGIN, &#8220;>myout.csv&#8221; or die &#8220;open .csv: $!&#8221;;\
    for my $line (keys %prod_margin) {
     print MARGIN $line, "\n";
    }
    close MARGIN
--------------------------------------------
plz help us.
Thanks
Sam


Posted by admin (Graham Ellis), 16 May 2008
Sample solution and code

earth-wind-and-fire:~ grahamellis$ perl pat
10 20 49 329 20
10, 20, 49, 329, 20
earth-wind-and-fire:~ grahamellis$ cat pat
@vals = (10,20,49,329,20);
print ("@vals\n");
print (join(", ",@vals),"\n");
earth-wind-and-fire:~



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.


WELL HOUSE CONSULTANTS LTD.: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho