Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-18-2013, 10:54 PM   PM User | #1
shadkeene
Regular Coder

 
Join Date: May 2007
Posts: 148
Thanks: 6
Thanked 0 Times in 0 Posts
shadkeene is an unknown quantity at this point
appending (s)printf output to string

I'm parsing some data and organizing it, and now I need to capture it inside a variable.

I've used printf in a manner like this to organize the data:
printf("%-30s %18s %18s\n", "$a", "$b", "$c\n");

Now I have a variable that's storing a string, and I want to append the organized data to the variable.

I tried something like $result.printf("%-30s %18s %18s\n", "$a", "$b", "$c\n");
and it doesn't work. I tried sprintf too.

Any ideas?

Thanks, S
shadkeene is offline   Reply With Quote
Old 03-19-2013, 12:34 AM   PM User | #2
shadkeene
Regular Coder

 
Join Date: May 2007
Posts: 148
Thanks: 6
Thanked 0 Times in 0 Posts
shadkeene is an unknown quantity at this point
solved

I had to place the sprint statement in a variable first, like this:

$result = printf("%-30s %18s %18s\n", "$a", "$b", "$c\n");

And then concatenate the two variables like this:

$result .= $final_result;

That solved it.
shadkeene is offline   Reply With Quote
Old 03-19-2013, 12:42 AM   PM User | #3
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,757
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
sprintf is what you're needing.

Code:
$result = 'some string value';

$result .= sprintf("%-30s %18s %18s\n", $a, $b, $c);
FishMonger is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:34 AM.


Advertisement
Log in to turn off these ads.