$# is deprecated, $OFMT doesn't work

D

Dan Jacobson

$ perl -wle '$#="%.2f";print 1/3'
Use of $# is deprecated at -e line 1.
0.33
$ man perlvar
$ perl -wle '$OFMT="%.2f";print 1/3'
Name "main::OFMT" used only once: possible typo at -e line 1.
0.333333333333333

What is the matter with me?
perl, v5.8.0
 
J

James Willmore

$ perl -wle '$#="%.2f";print 1/3'
Use of $# is deprecated at -e line 1.
0.33
$ man perlvar
$ perl -wle '$OFMT="%.2f";print 1/3'
Name "main::OFMT" used only once: possible typo at -e line 1.
0.333333333333333

What is the matter with me?
perl, v5.8.0

Why not just use printf?

jim@maxine:~> perl -wle 'printf "%.2f\n", 1/3'
0.33
jim@maxine:~>

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Life is like a simile.
 
S

Steven Smolinski

Dan Jacobson said:
$ perl -wle '$OFMT="%.2f";print 1/3'
Name "main::OFMT" used only once: possible typo at -e line 1.
0.333333333333333

Note to OP: in perlvar it should tell you that to use the long names of
the punctuation variables you need to:

use English;

But since $# is deprecated, see printf instead.


Question to everyone:

Should perlvar in 5.8.0 still mention $OFMT when it has been removed
from English.pm?

I don't know how to submit a documentation patch to p5p, but I suppose I
can learn.

Steve
 
T

Tassilo v. Parseval

Also sprach Dan Jacobson:
$ perl -wle '$#="%.2f";print 1/3'
Use of $# is deprecated at -e line 1.
0.33
$ man perlvar
$ perl -wle '$OFMT="%.2f";print 1/3'
Name "main::OFMT" used only once: possible typo at -e line 1.
0.333333333333333

If you want to use the long variable names for the punctuation
variables, you need the English module. However, $OFMT isn't handled by
that because $# is deprecated. Therefore:

*OFMT = \$#;
$OFMT = "%.2f\n";
print 1/3;
__END__
0.33

The first line will make $OFMT an alias for $#.

Tassilo
 
T

Tassilo v. Parseval

Also sprach Steven Smolinski:
Note to OP: in perlvar it should tell you that to use the long names of
the punctuation variables you need to:

use English;

But since $# is deprecated, see printf instead.


Question to everyone:

Should perlvar in 5.8.0 still mention $OFMT when it has been removed
from English.pm?

I just wondered about that, too, when I saw that alias to the deprecated
variables are commented out in English.pm. Either perlvar removes the
symbolic name of deprecated variables or the aliases remain in
English.
I don't know how to submit a documentation patch to p5p, but I suppose I
can learn.

perlvar.pod is just a plain file in the Perl source tree so you'd patch
it as any other file. See 'perldoc perlhack' for an instruction on how
to patch Perl and submit those patches.

Essentially: rsync one of the branches (blead, aka 5.9.0 or maint
[5.8.1-to-come]), cp pod/perlvar.pod to pod/perlvar.pod~ or so, patch
perlvar.pod, run

diff -u pod/perlvar.pod~ pod/perlvar.pod > patch

and send the patch as attachment to (e-mail address removed) while
mentioning against which branch this patch is (althouth the porters
might figure that out themselves).

Tassilo
 
T

Tassilo v. Parseval

Also sprach Abigail:
Steven Smolinski ([email protected]) wrote on MMMDCLXII
September MCMXCIII in <URL:news:[email protected]>:
)) Question to everyone:
))
)) Should perlvar in 5.8.0 still mention $OFMT when it has been removed
)) from English.pm?
))
)) I don't know how to submit a documentation patch to p5p, but I suppose I
)) can learn.


I've submitted a patch. Note that in the 5.8.1 track the OFMT
equivalent for $# was already removed from perlvar.

Hmmh, was it? I get (for RC1 though):

ethan@ethan:~$ perldoc5.8.1 -t perlvar | grep -A1 -m1 OFMT
$OFMT
$# The output format for printed numbers. This variable is a

Even in my not-so-lang-ago-synced blead perlvar.pod still mentions it.

Tassilo
 
T

Tassilo v. Parseval

Also sprach Abigail:
Tassilo v. Parseval ([email protected]) wrote on MMMDCLXII
September MCMXCIII in <URL:"" Also sprach Abigail:
"" > I've submitted a patch. Note that in the 5.8.1 track the OFMT
"" > equivalent for $# was already removed from perlvar.
""
"" Hmmh, was it? I get (for RC1 though):
""
"" ethan@ethan:~$ perldoc5.8.1 -t perlvar | grep -A1 -m1 OFMT
"" $OFMT
"" $# The output format for printed numbers. This variable is a
""
"" Even in my not-so-lang-ago-synced blead perlvar.pod still mentions it.


You are right. After submitting the patch, I grepped for OFMT as well,
but grepped against the patched file.

Haha, you first removed those occurances and immediately after that
checked whether they had been there at all in the first place? ;-)

Tassilo
 
A

Anno Siegel

[how to prepare a perl patch]
diff -u pod/perlvar.pod~ pod/perlvar.pod > patch

and send the patch as attachment to (e-mail address removed) while

Minor correction: Simply append the patch to the mail. Sending it
as an attachment actually makes it harder for the receiver, since
the patch program can deal directly with a mail message that ends
with a patch.

Anno
 
T

Tassilo v. Parseval

Also sprach Anno Siegel:
[how to prepare a perl patch]
diff -u pod/perlvar.pod~ pod/perlvar.pod > patch

and send the patch as attachment to (e-mail address removed) while

Minor correction: Simply append the patch to the mail. Sending it
as an attachment actually makes it harder for the receiver, since
the patch program can deal directly with a mail message that ends
with a patch.

That might be the best solution assuming you have a decent mailer. The
indecent ones are likely to render the patch unsubmittable by
introducing bogus line-breaks or such. Porting/patching.pod states:

Submitting your patch
Mailers
Please, please, please (get the point? :cool: don't use a mailer that
word wraps your patch. This leaves the patch essentially worthless
to the maintainers.

Unfortunately many mailers word wrap the main text of messages, but
luckily you can usually send your patches as email attachments
without them getting "helpfully" word wrapped.

I don't think my MUA is one of the evil ones, but the above somehow made
me cautious enough to always use attachments. I am a careful person. :)

Tassilo
 
A

Anno Siegel

Tassilo v. Parseval said:
Also sprach Anno Siegel:
[how to prepare a perl patch]
diff -u pod/perlvar.pod~ pod/perlvar.pod > patch

and send the patch as attachment to (e-mail address removed) while

Minor correction: Simply append the patch to the mail. Sending it
as an attachment actually makes it harder for the receiver, since
the patch program can deal directly with a mail message that ends
with a patch.

That might be the best solution assuming you have a decent mailer. The
indecent ones are likely to render the patch unsubmittable by
introducing bogus line-breaks or such. Porting/patching.pod states:

That is indeed another aspect. Don't patch sources with long lines :)
Submitting your patch
Mailers
Please, please, please (get the point? :cool: don't use a mailer that
word wraps your patch. This leaves the patch essentially worthless
to the maintainers.

Unfortunately many mailers word wrap the main text of messages, but
luckily you can usually send your patches as email attachments
without them getting "helpfully" word wrapped.

I don't think my MUA is one of the evil ones, but the above somehow made
me cautious enough to always use attachments. I am a careful person. :)

I did that too (send attachments), until someone (Hugo?) asked me not to.

When sending a patch from somewhere I haven't done it before, I mail it
to myself and see if it arrives in good shape.

Anno
 
S

Steven Smolinski

Tassilo v. Parseval said:
Also sprach Steven Smolinski:
I don't know how to submit a documentation patch to p5p, but I
suppose I can learn.

perlvar.pod is just a plain file in the Perl source tree so you'd patch
it as any other file. See 'perldoc perlhack' for an instruction on how
to patch Perl and submit those patches.
[...]

Thanks for the primer. Next time I won't let Abigail beat me to it.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,257
Messages
2,571,031
Members
48,768
Latest member
first4landlord

Latest Threads

Top