Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Think about Loose Coupling
 
PerlMonks

-localtime +gmtime

by Anonymous Monk
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Nov 06, 2009 at 09:18 UTC ( #805433=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Why does -localtime force scalar context but not +localtime?

print -localtime, $/; print +localtime, $/; print +gmtime, $/; print -+gmtime, $/; __END__ -Fri Nov 6 01:10:44 2009 4417161010953090 4417961010953090 -Fri Nov 6 09:10:44 2009

Comment on -localtime +gmtime
Download Code
Re: -localtime +gmtime
by moritz (Chancellor) on Nov 06, 2009 at 09:58 UTC
    B::Deparse to the help:
    $ perl -MO=Deparse -e 'print +localtime' print localtime; -e syntax OK $ perl -MO=Deparse -e 'print -localtime' print -localtime; -e syntax OK

    The + can be used to tell the parser that something isn't part of a function call, it's not a way to tell perl this is a number. We've just discussed this in Re: Split returning one element.

    In Perl 6 it is a bit different: foo(..), $x is always parsed a function call, followed by a comma and $x, whereas foo (...), $x is parsed a function call which receives both the parenthesis group and $x. That leaves the unary + free to force numeric context.

    Perl 6 - links to (nearly) everything that is Perl 6.
[reply]
[d/l]
[select]
Re: -localtime +gmtime
by ikegami (Saint) on Nov 06, 2009 at 16:05 UTC

    The no-op operator (unary-plus) doesn't even affect context. It is used to disambiguate parser decisions.

    Negation requires a number, so it forces numerical context. (Some convenient behaviour was added for when the argument isn't a number.)

[reply]

Back to Seekers of Perl Wisdom


Login:
Password
remember me
What's my password?
Create A New User

Node Status
node history
Node Type: perlquestion [id://805433]
Approved by broomduster
Front-paged by moritz
help
Community Ads
Chatterbox
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users
Others lurking in the Monastery: (6)
GrandFather
atcroft
herveus
Eyck
biohisham
gnosti
As of 2009-11-21 09:56 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Future historians will find that the material characteristic of the current era is...

Aluminium
Plastic
Oil
Water
Carbon dioxide
Copper
Iron
Silicon
Salt
Uranium
Hydrogen
Other

Results (729 votes), past polls