in reply to loop through values in a string and print " " around each value.

Try this ..
$str = "Leesville,TX,78122,830,48177,Gonzales,P,"; $str = "\"$str"; $str =~ s/\,/\"\,\"/g; $str =~ s/\"$//; print $str;
  • Comment on Re: loop through values in a string and print " " around each value.
  • Download Code

Replies are listed 'Best First'.
Re^2: loop through values in a string and print " " around each value.
by kevyt (Scribe) on Jan 12, 2007 at 04:20 UTC
    I dont know why I did not see this... This is a good solution. Save it as a var before I change it. Then push onto an array. Then loop through the array and print it.
    while ( <IN> ){ $str = $_; #### I added this chomp; tr/\"//d; if (/^#/){ ### added this push (@zips,$_); next; } if (I want this location){ . . . } else{ push (@zips,$str); } } # while foreach (@zips){ print ; }