Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

First I'll answer the quoting question. Try the following snippet.

my $text = "Hello world\n"; my $var = 'Hello world\n'; print $text; print $var;

In the case of $text, we used " (double quotes) and thus, \n was expanded to mean a newline. In the case of $var, we used single quotes, and \n remained the literal characters \ and n.

Now try this code:

my $text = "Hello world\n"; print "$text"; print '$text';

In the case of the first print statement, the variable $text is interpolated within the string (its value is put into the string). In the case of the second print statement, $text is the literal text printed.

Now for =>. => is sometimes called the "fat comma". It's most common use is in declaring elements of a hash, as in:

my %hash = ( This => 10, That => 20 );

The fat comma also has the effect of 'single quoting' the text immediately to its left. So the above snippet is equal to:

my %hash = ( 'This' , 10, 'That' , 20 );

Now for ->. That is used for dereferencing, which is an entirely different subject, having nothing to do with the => fat comma. If $aref is a reference to an array, one of the notations you can use to dereference that ref, and grab a single element is to use the dereference operator ->, like this: $aref->[3]. That's the same as:  ${$aref}[3], and a lot less ambiguous than something like $$aref[3].

As Zaxo has stated, you should have a look at perlsyn, perlop, and perlreftut.


Dave


In reply to Re: deference and inreference operators by davido
in thread deference and inreference operators by drock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-28 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found