Solved

Use of ==> to establish value in a scalar

Posted on 2007-12-01
3
159 Views
Last Modified: 2010-04-21
A book example has the line:

Readonly my $ACTIVE_LOG => '>temp.log<';

I thought => was used for hash list? Why was the => used instead of =  ?
0
Comment
Question by:lqwest
3 Comments
 
LVL 7

Accepted Solution

by:
Wod earned 75 total points
ID: 20389518
The => digraph is mostly just a synonym for the comma operator:

Comma Operator

Binary ``,'' is the comma operator. In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value. This is just like C's comma operator.

In list context, it's just the list argument separator, and inserts both its arguments into the list.

The => digraph is mostly just a synonym for the comma operator. It's useful for documenting arguments that come in pairs. As of release 5.001, it also forces any word to the left of it to be interpreted as a string.
0
 
LVL 17

Assisted Solution

by:mjcoyne
mjcoyne earned 50 total points
ID: 20389573
Likewise, a hash can be contructed from a comma-separated list:

#!/usr/bin/perl -w
use strict;

my %hash = ('apples', 'red', 'bananna', 'yellow');

foreach my $fruits (sort keys %hash) {
    print "$fruits are $hash{$fruits}\n"
}

0
 

Author Closing Comment

by:lqwest
ID: 31412145
I found some help also in the Perl's Best Practices book - basically has guideline that can be used when trying to decide if a => (aka fat comma) should be use: use it when you can say the symbol becomes blah-blah. Or as in my example ACTIVE_LOG becomes temp.log.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now