On 03/04/2013 11:22 AM, Chris Stinemetz wrote:
I would like to pass a list of variables to printf.
Is there a way to multiply a set printf length instead of
righting typing printf for each variable?
what I am trying to do is below:
printf "%-${longest}s x 27\n",
$rptType,$mkt,$ti
On 2013-03-04 20:27, Dr.Ruud wrote:
print sprintf +("| %-${wid}s" x @data)." |\n", @data;
Rather:
print sprintf +("| %-${wid}s " x @data) . "|\n", @data;
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://l
On 2013-03-04 17:22, Chris Stinemetz wrote:
I would like to pass a list of variables to printf.
Is there a way to multiply a set printf length instead of
righting typing printf for each variable?
what I am trying to do is below:
printf "%-${longest}s x 27\n",
$rptType,$mkt,$time
Am Sun, 02 Sep 2012 13:12:02 +0200
schrieb "Dr.Ruud" :
> On 2012-08-31 15:17, Torsten wrote:
>
> > I found a strange behaviour for printf: If you do for example
> >
> > printf "%d",29/100*100
> >
> > you get 28. But with
> >
> > printf "%d",29*100/100
> >
> > it's 29. Seems to be related to round
On 2012-08-31 15:17, Torsten wrote:
I found a strange behaviour for printf: If you do for example
printf "%d",29/100*100
you get 28. But with
printf "%d",29*100/100
it's 29. Seems to be related to rounding.
The perl version is 5.10.1 on debian.
There is nothing strange about it.
I think y
On Fri, 31 Aug 2012 15:28:38 +0300
"Octavian Rasnita" wrote:
> From: "Torsten"
>
> > Hey,
> >
> > I found a strange behaviour for printf: If you do for example
> >
> > printf "%d",29/100*100
> >
> > you get 28. But with
> >
> > printf "%d",29*100/100
> >
> > it's 29. Seems to be related to
From: "Torsten"
> Hey,
>
> I found a strange behaviour for printf: If you do for example
>
> printf "%d",29/100*100
>
> you get 28. But with
>
> printf "%d",29*100/100
>
> it's 29. Seems to be related to rounding.
Yep
use bignum;
might help.
Octavian
--
To unsubscribe, e-mail: beginne
> "PJ" == Paul Johnson writes:
>> 2,1,1,1175,2.58522727272727,1
>> 2,1,1,1175,,
>> 2,1,1,1175,1.354167,1
>> 2,1,1,1175,1.82765151515152,1
>> 2,1,1,1175,,
>> 2,2,1,1175,,
>> 8,1,1,1175,,
>> 10,2,1,1175,0.710227272727273,1
that is his output from MY version of the progr
On Fri, Mar 18, 2011 at 10:43:09PM -0600, Chris Stinemetz wrote:
> Hello,
>
> I would like to explicitly use printf '<%.2g>' for the element in the array
> called dist.
> Below is the error I am getting and below that is a sample of the output I
> can currently generate before I add printf.
>
>
> "CS" == Chris Stinemetz writes:
CS> I would like to explicitly use printf '<%.2g>' for the element in
CS> the array called dist. Below is the error I am getting and below
CS> that is a sample of the output I can currently generate before I
CS> add printf.
CS> Thank you
CS> Ar
Chas. Owens wrote:
On Mon, Jul 12, 2010 at 07:25, Rob Coops wrote:
snip
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)
snip
By that logic it should read
my @split_res
On Mon, Jul 12, 2010 at 07:25, Rob Coops wrote:
snip
> 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)
snip
By that logic it should read
my @split_result = split /:/
On Mon, Jul 12, 2010 at 12:54 PM, Shlomi Fish 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;
> >
> >
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, ">",
On Oct 27, 1:52 pm, aim...@sfbrgenetics.org (Aimee Cardenas) wrote:
> Hi, All!
>
> I need to fix the width of some strings padding with leading spaces if
> necessary. I wanted to use printf but I don't know if you can put a
> variable in the format part the the printf statement. For example,
> -Original Message-
> From: Aimee Cardenas [mailto:aim...@sfbrgenetics.org]
> Sent: Tuesday, October 27, 2009 15:53
> To: Perl Beginners
> Subject: printf
>
> Hi, All!
>
> I need to fix the width of some strings padding with leading
> spaces if
> necessary. I wanted to use printf bu
> "AC" == Aimee Cardenas writes:
AC> Awesome! Thanks, David! :-D
you can do it is true. but you should have been able to figure it out on
your own with simple logic or checking the docs. arguments to perl's
functions are just normal values and expressions. they may be converted
to someth
Awesome! Thanks, David! :-D
Aimee Cardenas
On Oct 27, 2009, at 4:56 PM, Wagner, David --- Senior Programmer
Analyst --- CFS wrote:
-Original Message-
From: Aimee Cardenas [mailto:aim...@sfbrgenetics.org]
Sent: Tuesday, October 27, 2009 15:53
To: Perl Beginners
Subject: printf
Hi
> Robert Citek wrote:
>> Not sure if there is a better way. My guess is that there is probably
>> some module to convert float to currency and then print it as a
>> string. But a quick Google didn't turn up anything.
>
> Here' why (extracted from `perldoc perllocale`):
>
>Category LC_MONET
Robert Citek wrote:
> Not sure if there is a better way. My guess is that there is probably
> some module to convert float to currency and then print it as a
> string. But a quick Google didn't turn up anything.
Here' why (extracted from `perldoc perllocale`):
Category LC_MONETARY: Formattin
I see. You want the output to look something like this:
$ perl -e 'for(my $total = 24.15; $total <3; $total *= 10) {
printf("Total:%10s\n", "\$" . sprintf("%.2f",$total)) ;} '
Total:$24.15
Total: $241.50
Total: $2415.00
Total: $24150.00
Not sure if there is a better way. My guess is
Is this what you are looking for:
$ perl -e '$total = 24.15 ; printf "Total: \$%.2f\n", $total; '
Regards,
- Robert
On Mon, Oct 26, 2009 at 11:57 AM, Bryan R Harris
wrote:
> Is there a good way to do printf's with currency symbols?
>
> I've tried this:
>
> printf "Total: \$%10.2f\n", $total;
>
On 10/26/09 Mon Oct 26, 2009 8:57 AM, "Bryan R Harris"
scribbled:
>
>
> Is there a good way to do printf's with currency symbols?
>
> I've tried this:
>
> printf "Total: \$%10.2f\n", $total;
>
> But it puts the dollar sign way out front (ugly). I want it to look like:
>
> Total:$
Jim Gibson writes:
> At 4:02 PM -0500 10/24/09, Harry Putnam wrote:
>>With this little script, how would I manage to get the shorter
>>timestamps zero padded using printf? I now how to get padded numbers
>>but not when I'm pushing off the right margin too.
>>
>>cat script.pl
>>
>> #!/usr/local
At 4:02 PM -0500 10/24/09, Harry Putnam wrote:
With this little script, how would I manage to get the shorter
timestamps zero padded using printf? I now how to get padded numbers
but not when I'm pushing off the right margin too.
cat script.pl
#!/usr/local/bin/perl
use strict;
use warnin
On Oct 29, 8:22 pm, [EMAIL PROTECTED] (Julie A. Bolduc) wrote:
> I am trying to format some numbers so single digit numbers are converted to
> 2 digit numbers and here is the code I am working with right now. For some
> reason, the very last number, $b5, ends up as a 3 digit number instead of a
>
try using sprintf instead of printf.
i think the extra 1 you are getting on the end it just a true return.
-Original Message-
From: Julie A. Bolduc [mailto:[EMAIL PROTECTED]
Sent: 30 October 2007 00:23
To: beginners@perl.org
Subject: printf problem
I am trying to format some numbers so s
On 18 Jan 2007 at 16:25, Eugene Kosov wrote:
> Beginner wrote:
> > Hi all,
> >
> > Sorry I am sure this is a lame question.
> >
> > I want to print out some column (with heading) and I want them
> > evenly spaced. I know this is a printf but the format eludes me.
> >
> > printf("%c12", $var);
On 18 Jan 2007 at 7:19, Hal Wigoda wrote:
> for one thing, you need to add "\n" for newline.
> > printf("%c12", $var); # prints $var12$var12
> >
> > %s seems to give me no output at all.
> >
I wouldn't want a newline in the middle of my column heading. I would
like a 12 character spacing betw
Beginner wrote:
Hi all,
Sorry I am sure this is a lame question.
I want to print out some column (with heading) and I want them evenly
spaced. I know this is a printf but the format eludes me.
printf("%c12", $var); # prints $var12$var12
Try %12c (or %12s) instead of %c12 above.
--
To u
for one thing, you need to add "\n" for newline.
On Jan 18, 2007, at 7:12 AM, Beginner wrote:
Hi all,
Sorry I am sure this is a lame question.
I want to print out some column (with heading) and I want them evenly
spaced. I know this is a printf but the format eludes me.
printf("%c12", $var)
R. Joseph Newton wrote:
> All the use one could imagine. The printf function can print pretty much
> anywhere. I believe that it preceded sprintf historically, but I wouldn't
> swear
>
> Many C coders have told me that it is the most efficient way to
> write files.
huh? please explain why prin
Paul Kraus wrote:
> What is the difference. The only I see is that printf can take a filehandle?
> But what use would that be.
All the use one could imagine. The printf function can print pretty much
anywhere. I believe that it preceded sprintf historically, but I wouldn't swear
to it. Many C
> Wiggins D Anconia wrote:
> >
> > Notice the difference in the docs:
> >
> > printf FILEHANDLE FORMAT, LIST
> > printf FORMAT, LIST
> >
> > In the first there is NO comma following the filehandle, this means it
> > is interpreted in a different manner than the rest of the argument list,
> > or p
Wiggins D Anconia wrote:
>
> Notice the difference in the docs:
>
> printf FILEHANDLE FORMAT, LIST
> printf FORMAT, LIST
>
> In the first there is NO comma following the filehandle, this means it
> is interpreted in a different manner than the rest of the argument list,
> or probably to be more pre
Wiggins D Anconia wrote:
>
> Notice the difference in the docs:
>
> printf FILEHANDLE FORMAT, LIST
> printf FORMAT, LIST
>
> In the first there is NO comma following the filehandle, this means it
> is interpreted in a different manner than the rest of the argument list,
> or probably to be more pre
> > > What is the difference. The only I see is that printf can
> >
> > One difference is printf prints it's output and sprintf
> returns it';s
> value.
> >
> > printf ...
> > my $formatted_goodies = sprintf ...
> >
> > > take a filehandle? But what use would that be.
> > >
> >
> > To format
> > What is the difference. The only I see is that printf can
>
> One difference is printf prints it's output and sprintf returns it';s
value.
>
> printf ...
> my $formatted_goodies = sprintf ...
>
> > take a filehandle? But what use would that be.
> >
>
> To format the contents of it. For
>
> What is the difference. The only I see is that printf can take a
filehandle?
> But what use would that be.
>
The filehandle tells printf where to print the result, aka which
filehandle, by default STDOUT. Which doesn't have a purpose with
sprintf since it returns its value...
http://dan
> What is the difference. The only I see is that printf can
One difference is printf prints it's output and sprintf returns it';s value.
printf ...
my $formatted_goodies = sprintf ...
> take a filehandle? But what use would that be.
>
To format the contents of it. For instance, you might hav
On Mon, Dec 22, 2003 at 11:17:03AM -0800, Perl wrote:
> i know what " %9.1f" would have done in this case.
> but how does " %9.2g" round off ?
The *rounding* works like "%f", but there are some other
differences.
a) the precision (".2") applies to significant digits, not
digits after the d
Am Montag, 22. Dezember 2003 20:17 schrieb Perl:
> i know what " %9.1f" would have done in this case.
> but how does " %9.2g" round off ?
the FORMAT notation used by prinf, sprintf, ... can be found on
http://www.perldoc.com/perl5.8.0/pod/func/sprintf.html
which gives:
%e a floating-point
Am Montag, 22. Dezember 2003 20:17 schrieb Perl:
> i know what " %9.1f" would have done in this case.
> but how does " %9.2g" round off ?
the FORMAT notation used by prinf, sprintf, ... can be found on
http://www.perldoc.com/perl5.8.0/pod/func/sprintf.html
which gives:
%e a floating-point
McMahon, Chris wrote:
> Hi Wags...
> So now an idle style question, if you don't mind...
>
> This syntax seems pretty obscure to me (I had to look up what printf
> was doing):
>
> printf "%3d $file\n", $MyId++;
>
> It's efficient and all, but isn't this more readable for the sa
Well, atleast I was right about the padding :)
LoBue, Mark wrote:
-Original Message-
From: Andrew Gaffney [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 05, 2003 3:21 PM
To: [EMAIL PROTECTED]
Subject: Re: printf? RE: help building hash on-the-fly?
I'm going to venture a guess
> -Original Message-
> From: Andrew Gaffney [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, November 05, 2003 3:21 PM
> To: [EMAIL PROTECTED]
> Subject: Re: printf? RE: help building hash on-the-fly?
>
>
> I'm going to venture a guess here. Its probably be
I'm going to venture a guess here. Its probably because he needed the number printed as a
3-digit number padded with zeroes, which print can't do.
McMahon, Chris wrote:
Hi Wags...
So now an idle style question, if you don't mind...
This syntax seems pretty obscure to me (I had to look up
On Jul 1, Jeff 'japhy' Pinyan said:
>On Jul 1, Ned Cunningham said:
>
>>Can anyone tell me how to print the following data so that it rounds up
>>even though it shouldn't
>
>Use the POSIX::ceil() function, instead of some crufty solution.
>
> use POSIX 'ceil';
> printf WRFILE "%11.2f", ceil
On Jul 1, Ned Cunningham said:
>Can anyone tell me how to print the following data so that it rounds up
>even though it shouldn't
Use the POSIX::ceil() function, instead of some crufty solution.
use POSIX 'ceil';
printf WRFILE "%11.2f", ceil($data);
--
Jeff "japhy" Pinyan [EMAIL
You could always try adding .999 to the value before sprintf()ing it...
-Original Message-
From: Ned Cunningham [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 01, 2002 11:32 AM
To: '[EMAIL PROTECTED]'
Subject: printf question
Hi,
Can anyone tell me how to print the following data so th
on Mon, 01 Jul 2002 18:32:27 GMT, Ned Cunningham wrote:
> Can anyone tell me how to print the following data so that it rounds
> up even though it shouldn't
> $data = "3.424";
> [...]
> I need it to round up even if it is only .001 ?
use strict;
use POSIX qw(ceil);
sub rou
EMAIL PROTECTED]'
Subject:RE: printf question
correction on my 4th line.
$data = sprintf ("%11.2f", $data + (scalar($data =~
/[1-9]$/) && 0.005) );
> -Original Message-
> Fr
correction on my 4th line.
$data = sprintf ("%11.2f", $data + (scalar($data =~ /[1-9]$/) && 0.005) );
> -Original Message-
> From: Nikola Janceski [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 01, 2002 2:55 PM
> To: 'Ned Cunningham'; '[EMA
I don't know what accuracy you need.. but:
#my $data = "3.420";
my $data = "3.424";
$data = sprintf ("%11.3f", $data);
$data = sprintf ("%11.2f", $data + scalar($data =~ /[1-9]$/) / 100 );
printf ("%11.2f\n", $data);
> -Original Message-
> From: Ned Cunningham [mailto:[EMAIL PROTECTED]]
"Adrian Farrell" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> $answer = printf ("\nThe area of the circle with a radius of $radius is
> %2.2f\n", ($area));
>
> print "$answer"
If you want to store the string in a var, use sprintf. printf returns wether
or
> "Adrian" == Adrian Farrell <[EMAIL PROTECTED]> writes:
Adrian> The problem is that $answer returns a value of 1 and not the
Adrian> contents of the printf. I guess I've assigned it
Adrian> incorrectly. the other odd thing is that the -- print
Adrian> "$answer" -- line appear
I don't know of a searchable archive.
To format the number you can either roll your own, grab the solution in the
Perl Cookbook, or use Number::Format.
http://search.cpan.org/search?mode=module&query=Number%3A%3AFormat
use Number::Format;
my $commaNum = new Number::Format(-thousands_sep => '.
On Mar 15, Brian Warn said:
>Hi, two questions: is there an easy way -- using printf, etc. -- to
>format 100 such that it appears as 1,000,000? Also, is there a
>searchable archive of the beginner list anywhere?
As per commas, the Perl FAQ has the answer:
perldoc -q commas
As for the a
try ...
if ( ! $size ) { $size = 8 }
printf " %${size}s ", $yourVariableHere;
?frank
-Original Message-
From: Nikola Janceski [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 30, 2002 4:21 PM
To: '[EMAIL PROTECTED]'
Subject: printf using a variable for the field size
I am trying
On Jan 30, Nikola Janceski said:
>printf " %8s ", $_; ## works because I put the 8 in the code
>
>but what if the variable $size has the size, how then do I use printf using
>$size in place of the 8?
Two ways come to mind:
printf " %${size}s ", $_;
and
printf " %*s ", $size, $_;
--
Jeff
On Mon, 10 Sep 2001, Derrick (Thrawn01) wrote:
> Now that I think about it it could be done like this
>
> @tary = unpack "a4a2a2", @data[0]->[17];
> $last_open = "$tary[0]-$tary[1]-$tary[2]";
>
> But wich would be faster ? would unpack be faster than the exp engine?
>
> Anyone's thoughts ?
I bet
> "Derrick" == Derrick <[EMAIL PROTECTED]> writes:
Derrick> Now that I think about it it could be done like this
Derrick> @tary = unpack "a4a2a2", @data[0]->[17];
Can we please stop using the illegal syntax there?
$data[0][17] or $data[0]->[17] or ${$data[0]}[17], but not @data[0]->...
Th
rett W. McCoy [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 10, 2001 11:03 AM
To: Derrick (Thrawn01)
Cc: Perl Beginners
Subject: Re: printf to convert 200010809 to 2001-08-09
On Mon, 10 Sep 2001, Derrick (Thrawn01) wrote:
> @data[0]->[17] contains "20010809"
>
> I've
Either of these will work -- I'll leave it up to the experts to let us know
which one (if any) is faster or more efficient:
$last_open = sprintf '%04d-%02d-%02d', $data[0]->[17] =~
/^(\d{4})(\d{2})(\d{2})$/;
$last_open = sprintf '%04d-%02d-%02d', unpack 'A4A2A2', $data[0]->[17];
Please note tha
Thanks for the help, I think this will work out.
oh. Unusual site you have there.
-Original Message-
From: Brett W. McCoy [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 10, 2001 11:03 AM
To: Derrick (Thrawn01)
Cc: Perl Beginners
Subject: Re: printf to convert 200010809 to 2001-08
Derrick schrieb:
>
> @data[0]->[17] contains "20010809"
>
> I've been tring to use printf to convert the 200010809 value out as
> 2001-09-08
>
> $last_open = sprintf "%4d-%2d-%2d",@data[0]->[17];
>
> However this does not work. I get "20010809- 0- 0"
> Any sugesstions on how I should make this
On Mon, 10 Sep 2001, Derrick (Thrawn01) wrote:
> @data[0]->[17] contains "20010809"
>
> I've been tring to use printf to convert the 200010809 value out as
> 2001-09-08
>
> $last_open = sprintf "%4d-%2d-%2d",@data[0]->[17];
>
> However this does not work. I get "20010809- 0- 0"
> Any sugesstions
make your %4d-%2d-%2d look like %4d-%02d-%02dThe zero with the number says
to have zero fill instead of blank fill.
Wags ;)
-Original Message-
From: Derrick (Thrawn01) [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 10, 2001 07:57
To: Perl Beginners
Subject: printf to con
Govinderjit Dhinsa wrote:
>
> How could I please put the following example;
>
> 1000.000
> 10.000
> 100.000
> 1.000
> To please print out, IN A LINE with the Decimal Place! and not from the
> first number, so all the decimal places would line up!
> example;
>
> I have tried prin
You haven't been using printf correctly. Try
foreach (qw(
1000.000
10.000
100.000
1.000))
{
printf "%13.6f\n", $_;
}
The %13.6 gives a total field width of 13 and 6 decimal places. Same as C. The
default is to r
. This way you can line up the decimal points." Unquote
- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, September 06, 2001 9:43 AM
Subject: RE: Printf
> You could try someth
You could try something like this:
###
use strict
@a = qw(10.000 100.00 100.0 1000.000);
$a = $b = "";
foreach $val (@a) {
($a,$b) = split(/\./,$val);
write;
}
format STDOUT =
@>.@<
$a,$b
.
###
> -Original Message-
On Thu, 6 Sep 2001, Govinderjit Dhinsa wrote:
> How could I please put the following example;
>
> 1000.000
> 10.000
> 100.000
> 1.000
> To please print out, IN A LINE with the Decimal Place! and not from the
> first number, so all the decimal places would line up!
> example;
>
> I
At 09:52 12.07.2001 +0100, Govinderjit Dhinsa wrote:
>Does any body know why the printf is not printing anything out!
>
>I tested the rest of the script by replacing the printf line with,
>##
>print "$line";
>##
>the file prints (with out any changes to the file, as expected). So
>
On Thu, Jul 12, 2001 at 09:52:32AM +0100, Govinderjit Dhinsa wrote:
> Does any body know why the printf is not printing anything out!
>
> I tested the rest of the script by replacing the printf line with,
> ##
> print "$line";
> ##
> the file prints (with out any changes to the fi
Does any body know why the printf is not printing anything out!
I tested the rest of the script by replacing the printf line with,
##
print "$line";
##
the file prints (with out any changes to the file, as expected). So
everything else is working apart from the printf.
Any help w
On Mon, Jul 02, 2001 at 09:58:43AM +0100, Govinderjit Dhinsa wrote:
> $fields[0],$fields[5],$fields[70],$fields[71],$fields[72],$fields[75],$field
> s[76],$fields[77],$fields[78],$fields[79];
If I couldn't get away with this atrocious by-position form (a hash, with
sanely named and thus self-docu
Hello Govinderjit Dhinsa,
Monday, July 02, 2001, Govinderjit Dhinsa <[EMAIL PROTECTED]> wrote:
GD> printf
GD> sortcode"\n%6.6s1%20.20s%45.35s%30.30s%30.30s%30.30s%4.4s%4.4s%8.6s%8.8s",
GD> $fields[0],$fields[5],$fields[70],$fields[71],$fields[72],$fields[75],$field
GD> s[76],$f
printf has the f on the end because it expects a format string. If you
are on a unix box try typing "man 3 printf". This shows you the docs
for C's printf, but since perl's printf is does a straight pass thorugh
to C's printf that shouldn't matter. Try this in your code:
printf sortcode "%s %
Govinderjit Dhinsa [mailto:[EMAIL PROTECTED]] wrote:
> I can not get the printf to print, using the following
> relevant line of
> code:
> printf sortcode $fields[0],$fields[5],$fields[70],fields[77];
>
> I am missing something in-between;
> sortcode *$fields[0]
>
Is sort c
Michael Fowler wrote:
> On Tue, Jun 05, 2001 at 08:05:24AM -0400, Herb Hall wrote:
> > $min = "0" . $min if $min < 10;
> >
> > will pad your minutes with a 0. I have used both methods for various
> > reasons. You probably only need to use one or the other. I would use the
> > printf unless you hav
On Tue, Jun 05, 2001 at 08:05:24AM -0400, Herb Hall wrote:
> $min = "0" . $min if $min < 10;
>
> will pad your minutes with a 0. I have used both methods for various
> reasons. You probably only need to use one or the other. I would use the
> printf unless you have some need to have the variables
> ### get time
> my($sec, $min, $hour, $mday, $month, $year) = (localtime)[0..5];
> $year += 1900;
> $mday = "0" . $mday if $mday < 10;
> $month++; # perl counts from -1 on occasion
> $month = "0" . $month if $month < 10;
>
>
> -- later in the same file --
>
> print TOFILE "On $month/$mday/$y
David Gilden wrote:: ##this does not work
:
: print ($sort_order) ? 'Newest First' : 'Oldest First';
Perl thinks you're doing this:
print($sort_order) ? 'Newest First' : 'Oldest First';
that is, it's taking $sort_order as an argument to print().
Either remove the parens:
print $sort_ord
David Gilden wrote:
> Is there a way to combine the last two statements?
[...]
> $sort_type = ($sort_order) ? 'Newest First' : 'Oldest First';
> # are the () optional?
>
> print $sort_type;
print $sort_order ? 'Newest First' : 'Oldest First';
or
print( $sort_order ? 'Newest Fi
I'll just answer the 'other stuff'.
> ##this does not work
>
> print ($sort_order) ? 'Newest First' : 'Oldest First';
Perl sees this as a function() call followed by the rest.
Instead, do:
> print $sort_order ? 'Newest First' : 'Oldest First';
In general, Perl works to minimize the numbe
On Jun 1, David Gilden said:
>$sort_order =0;
>
>$sort_type = ($sort_order) ? 'Newest First' : 'Oldest First';
># are the () optional?
In this case, yes, you don't need those parens.
>print ($sort_order) ? 'Newest First' : 'Oldest First';
Remove the parens, or add them around the entire argume
On Fri, Jun 01, 2001 at 03:05:59PM -0400, David Gilden wrote:
[snip -- was there a question about '?:' ?]
> printf question--
>
> ### get time
> my($sec, $min, $hour, $mday, $month, $year) = (localtime)[0..5];
> $year += 1900;
> $mday = "0" . $mday if $mday < 10;
> $month++; # perl counts fr
Remove the ()'s and it works.
For the 0's:
printf "On %02d/%02d/%04d At %02d:%02d you wrote:\n\n", $month, $mday,
$year, $hour, $min;
see perldoc -f printf for more info.
- Original Message -
From: "David Gilden" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 01, 2001 1:05
89 matches
Mail list logo