On Mon, Jul 12, 2010 at 12:54 PM, Shlomi Fish <shlo...@iglu.org.il> wrote:
> On Monday 12 Jul 2010 11:07:49 newsense wrote: > > This is what i currently have but am not sure how i can use printf > > here instead of print so i can get some nice columns. > > > > #!/usr/bin/perl > > use warnings; > > use strict; > > > > open my $list, "<", "proxylist.txt" or die $!; > > open my $outfile, ">", "test.txt" or die $!; > > > > while (<$list>) { > > print $outfile (join(" ", "socks5", split /:/ )); > > } > > It depends how many columns you have and how wide each one of them should > be. > See the printf / sprintf tutorial at: > > http://perl-begin.org/tutorials/perl-for-newbies/part4/#page--sprintf--DIR > > Regards, > > Shlomi Fish > > -- > ----------------------------------------------------------------- > Shlomi Fish http://www.shlomifish.org/ > Best Introductory Programming Language - http://shlom.in/intro-lang > > God considered inflicting XSLT as the tenth plague of Egypt, but then > decided against it because he thought it would be too evil. > > Please reply to list if it's a mailing list post - http://shlom.in/reply . > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > Currently you are doing something neat but also confusing for a lot of beginning per coders, you are in the following line: print $outfile (join(" ", "socks5", split /:/ )); splitting the $_ variable (if no variable is explicitly handed to split it operates on $_) then instantly joining the output with the string "socks5" at the start and a " " between every value that the split has returned. In other words you are using a function inside a function. If you split this into two lines. my @split_result = split /:/; print $outfile join(" ", "socks5", @split_result) With a setup like that you are most likely able to workout a nice printf statement that prints the various variables correctly. It would not be any fun if I just tell you how to do the whole thing in the end you want to remember how to do these sorts of things and the best way to do that is by working it out for your self as Shlomi pointed out before the printf manual should provide you all the information you need to work it out from here. Rob