Alright, I sort of understand now.

This is my "more Perlish" proposal:

#!/usr/bin/perl use strict; use warnings; my $first_line = <DATA>; chomp $first_line; $first_line =~ s/,/chr(31)/eg; print $first_line, chr(30); while (<DATA>) { chomp; my @fields = split /,"|",/; $fields[2] =~ s/,/chr(31)/eg; print join chr(31), @fields, chr(30); } __DATA__ Country,Name,Address,Age Andorra,"Aileen, Daquan, Hammett, Malachi",17014,69 Solomon Islands,"Cyrus, Giacomo, Gretchen, Curran",76935,26 Czech Republic,"Briar, Larissa, Sybil, Colin",29565,88 (...)
As such, the program produces the same strange looking output as the one I've shown before:
CountryNameAddressAgeAndorraAileen, Daquan, Hammett, Malachi1701469Solomon IslandsCyrus, Giacomo, Gretchen, Curran7693526Czech RepublicBriar,
But once piped to the other program that you have shown, this produces, I believe, the same output as your program piped into the same second program:
Country|Name|Address|Age Andorra|Aileen, Daquan, Hammett, Malachi|17014|69| Solomon Islands|Cyrus, Giacomo, Gretchen, Curran|76935|26| Czech Republic|Briar, Larissa, Sybil, Colin|29565|88| Japan|Wyatt, Gavin, Derek, Coby|10734|52| (...)
The full output is displayed below:

Country|Name|Address|Age Andorra|Aileen, Daquan, Hammett, Malachi|17014|69| Solomon Islands|Cyrus, Giacomo, Gretchen, Curran|76935|26| Czech Republic|Briar, Larissa, Sybil, Colin|29565|88| Japan|Wyatt, Gavin, Derek, Coby|10734|52| Gabon|Tobias, Maya, April, Quintessa|77397|95| Jersey|Reece, Clarke, Idona, Troy|85473|73| Finland|Paul, Quamar, Leigh, Adara|09441|66| Tanzania|Dexter, Macaulay, Colorado, Lucas|47636|56| Djibouti|Rhonda, Minerva, Thomas, Francis|41040|78| British Indian Ocean Territory|Beck, Kiara, Nathan, Rhiannon|42270|59| Marshall Islands|Evangeline, Drew, Joan, Ignatius|11305|37| Albania|Sigourney, Brock, Colette, Wynne|15359|34| Ireland|Wilma, Lacota, Clare, Chiquita|35334|85| South Africa|Lacey, Tamara, Abigail, Ursa|54094|15| Albania|Eliana, Tarik, Plato, Lucy|10625|98| Burundi|Sara, Kay, Bo, Miriam|11557|82| Trinidad and Tobago|Griffin, Claire, Sage, Leroy|71860|46| Timor-Leste|Fletcher, Britanney, Heather, Stella|14227|49| Macao|Nicole, Brittany, Mark, Reese|52189|35| Niue|Sawyer, Ferris, Josiah, Halla|16491|23| Singapore|Brock, Emerald, Veronica, Derek|41836|73| Syria|Keane, Basia, Wyoming, Orla|27003|80| Micronesia|Jared, Beverly, Kimberly, Richard|87004|31| South Africa|Amy, Chaim, Xandra, Raven|83099|73| France|Barbara, Jerry, Karyn, Ray|63790|19| Cocos (Keeling) Islands|Jaden, Natalie, Eugenia, Adrian|29692|7| Tonga|Barrett, Chaney, Adena, Aurora|78475|38| Turkmenistan|Echo, Freya, Ethan, Jeanette|50055|58| Bermuda|Keely, Laura, Winter, Dakota|21429|5| Mayotte|Hedy, Jescie, Randall, Chancellor|27322|45| Spain|Ora, Tashya, Linda, Velma|25194|30| Slovenia|Tucker, Allegra, Mari, Hu|48334|80| Honduras|Abbot, Cheryl, Alana, Owen|96426|39| Holy See (Vatican City State)|Rigel, Illiana, Ignacia, Hope|55041|62| Tonga|Caryn, Shoshana, Hilel, Amanda|36756|44| Sweden|Pandora, Charity, Mariko, Cathleen|14178|41| Holy See (Vatican City State)|Katelyn, Otto, Francis, Karina|51371|77| Armenia|Emmanuel, Sara, Veda, Yolanda|84455|24| Cayman Islands|Deborah, Randall, Stacy, Melvin|73680|77| "Bonaire, Sint Eustatius and Saba|"Charissa, Lana, Liberty, Quail|4451 +7|18| Northern Mariana Islands|Fitzgerald, Jorden, Harrison, Cora|13262|95| Iran|Joshua, Fredericka, Noah, Erich|75209|91| Finland|Neil, Natalie, Sheila, Gisela|65124|56| Australia|Knox, Quinn, Warren, Tanisha|62518|65| Bahrain|Hayes, Alvin, Imogene, Heather|36073|50| Botswana|Justina, Xena, Maite, Tanner|20482|93| Antigua and Barbuda|Leroy, TaShya, Malachi, Jennifer|04462|48| Turkey|Gretchen, Iona, Kim, Alice|87848|54| Martinique|Carl, Blaze, Kenyon, Tallulah|82059|99| Macao|Hiram, Graiden, Joshua, Quail|45176|71| Botswana|Hammett, Zeus, Kadeem, Kasimir|22147|47| Brunei|Quentin, Darrel, Roanna, Paul|73691|26| Solomon Islands|Dominic, Brynne, Sonia, Phillip|06263|48| Poland|Roanna, Quentin, Barrett, Ciara|24730|83| Isle of Man|Illana, Stewart, Nita, Arden|57975|75| Libya|Channing, Darius, Pandora, Hedda|88969|90| Haiti|Rama, Francesca, Nyssa, Gray|50404|20| Hungary|Garth, Colton, Brody, Jael|84951|69| Malaysia|Hashim, Todd, Olga, Amelia|00953|13| Saudi Arabia|Anne, Basil, Walter, Chaney|93043|90| Saudi Arabia|Rudyard, Cassady, Myra, Kaseem|19202|62| Australia|Montana, Jackson, Lavinia, Raja|18775|34| Myanmar|Camilla, Arden, Stephanie, Bruce|17434|4| Kenya|Olympia, Michelle, Emerald, Judah|31399|50| Latvia|Karen, Jared, Celeste, Dana|33911|48| Somalia|Hammett, Tyrone, Caryn, Ima|91423|5| Wallis and Futuna|Amela, Medge, Zephania, Chase|13922|69| Mayotte|Freya, Mara, Madison, William|97119|27| Sao Tome and Principe|Sara, Sheila, Anthony, Bruno|62269|4| Saint Martin|Carlos, Brian, Carson, Kylynn|96705|74| Bolivia|Herman, Brynn, Jamalia, Quemby|70279|41| Nicaragua|Quin, Ira, Kiona, Calista|92169|87| Gabon|Catherine, Olga, Hashim, Deirdre|06748|26| Swaziland|Inez, Charde, Kalia, Ferdinand|06392|64| Ethiopia|Karyn, Martha, Honorato, Leroy|81013|74| Reunion|Jonas, Inez, Quinn, George|45690|2| "Virgin Islands, British|"Otto, Macon, Caldwell, Sasha|87676|49| Botswana|Sean, Jordan, Hu, Octavius|26531|4| Egypt|Karleigh, David, Marsden, Emi|53564|84| Lesotho|Marcia, Melyssa, Hayfa, Kasper|78219|12| Burundi|Tana, Reece, Deirdre, Asher|01186|84| Greenland|Zelda, Dale, Adara, Randall|50939|13| Macao|Blaze, Carol, Ryan, Jamal|85508|24| Seychelles|Gwendolyn, Harrison, Lee, Martha|89440|1| Senegal|Thaddeus, Shana, Bryar, Louis|64079|45| Qatar|Anastasia, Maggy, Joshua, Byron|05381|41| Pakistan|Jamal, Hanna, Emmanuel, Ira|09657|75| Angola|Jacob, Kennedy, Ross, Ria|82465|19| Estonia|Alexa, Geraldine, Dexter, Maisie|81424|63| Northern Mariana Islands|Anthony, Dana, Colorado, Emi|03919|33| Barbados|Lev, Harlan, Adria, Abraham|23897|41| Paraguay|Regan, Amos, Quemby, Lysandra|93955|13| China|Harrison, Leslie, Steven, Gemma|58927|40| Philippines|Dante, George, Amaya, Dante|23359|9| Saint Kitts and Nevis|Charles, Ronan, Dakota, Hiram|38760|3| Martinique|Nichole, Maisie, Vernon, Leah|80565|70| Iran|Ignacia, Nicholas, Richard, Clarke|38992|38| Antarctica|Iliana, Octavius, Serena, Guinevere|57025|10| Micronesia|Alexander, Angela, Wylie, Axel|19982|82| Bangladesh|Claire, Laura, Phillip, Pascale|70016|5|

As you can see, "more Perlish" often means much shorter code (although I really did not try to make it particularly concise and I decided, for simplicity, to process the header line separately. If you ignore that and forget about boiler plate code at the beginning, the real program holds in 5 lines). I also think that, on very large input, my version is most probably considerably faster.

I'll be glad to give more information if there is anything you don't understand.


In reply to Re: Suggestions to make this code more Perlish by Laurent_R
in thread Suggestions to make this code more Perlish by ricardo_sdl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.