Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This is puzzling...

perlref says "Anywhere you’d put an identifier (or chain of identifiers) as part of a variable or subroutine name, you can replace the identifier with a BLOCK returning a reference of the correct type."

We can see from ELISHEVA's example that the sub is called in list context. I assume, therefore, that it returns a list. But a list isn't "a reference" even if every element of the list is. Is there an undocumented case of the block returning a list? Or am I wrong to think that the sub returns a list? If it doesn't return a list, what does it return and why?

Had the sub been called in scalar context then, because there is no such thing as a list in scalar context, what does \(LIST) become?

sub foo { \('fred', 'bill') };; print "${ scalar(foo()) }"; __END__ Returns: bill

So I know what happens in the end, but I'm having trouble reconciling my model of what perl does and what the various expressions mean.

update: Considering JavaFan's post I see my mistake: the sub is called in scalar context, not list context. The call is not the same as in ELISHEVA's original post. And perlref says \($a, $b, $c) is the same as (\$a, \$b, $\c). I conclude that in scalar context the latter is simply not a list.

update2: Changed "array context" to "list context" throughout, because that's what it is called.

update3: Clarified what perlref says and what I conclude/assume.

In reply to Re^2: Why does foo() evaluate in array context in "${\foo()}"? by ig
in thread Why does foo() evaluate in array context in "${\foo()}"? by ELISHEVA

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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2023-03-28 03:13 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (66 votes). Check out past polls.