Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to create a tab delimited entry, 1 line at a time...

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
i have this info:

$string="123456,smith-john,11.10,april payment,USD|123499,jones-mike,40.99,april payment,USD|123994,jackson-sam,44.11,april payment,USD";

and i'd like to save into a file as:

123456 smith-john 11.10 april payment USD
123499 jones-mike 40.99 april payment USD
123994 jackson-sam 44.11 april payment USD

where the spaces are tabs.

this is for a paypal masspay file.

i know how to seperate the string and save line by line to a text file, i just can't figure out how to include the tabs in the text file, too.

any ideas?

- g
 
You can do it in one line:
Code:
my $string="123456,smith-john,11.10,april payment,USD|123499,jones-mike,40.99,april payment,USD|123994,jackson-sam,44.11,april payment,USD";

$string =~ y/,|/\t\n/;

print "$string\n";
i.e. replace commas with tabs (\t) and pipes with newlines (\n).

That code assumes you won't have commas or pipes elsewhere in the file, in which case you'll need a proper CSV parser.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top