Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Howdy, venerable monks! Is there a way to hang some non-looped output on the end of a statement modifier, like print "$_\n" for 1..3, "\n\n" (that doesn't do what I want, of course, but you can see what I'm saying.)

Replies are listed 'Best First'.
Re: Statement modifier thingie
by BrowserUk (Patriarch) on Mar 01, 2012 at 04:39 UTC

    This has the affect you want, at least for the example supplied:

    print join "\n", 1..3, "\n";; 1 2 3

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      I think that's three people saying "Give it up, Keith; she's dead, buried, forgotten, and even the life insurance money's all been drunk up." All righty, then - thanks, all you wise Perl Monks!

        Que?

Re: Statement modifier thingie
by davido (Cardinal) on Mar 01, 2012 at 06:00 UTC

    It's not a statement modifier, but it is a "loopy thing".

    print( ( map { "$_\n" } 1 .. 3 ), "\n\n" );

    ...but why?


    Dave

Re: Statement modifier thingie
by Anonymous Monk on Mar 01, 2012 at 03:57 UTC
      'K, I'll try to say it a different way: is there a way for me to use a statement modifier like print "$_\n" for 1..3 and add something to the end of it, like an extra newline, that doesn't mess with the loop but just gets printed after it? I've tried parens, brackets, commas, the dot, and mayonnaise with ketchup smeared nice and even, but none of it works (and some is pretty messy.) Is there a way to do it?
        No.
Re: Statement modifier thingie
by rovf (Priest) on Mar 01, 2012 at 10:51 UTC
    No, because the statement modifier would then be an expression modifier, not a statement modifier. Think about what exactly is a "statement" in Perl!

    -- 
    Ronald Fischer <ynnor@mm.st>
      Yeah, statements are constructs like:
      if ($foo) {print "Hello"}; package Foo 1.2.3; use Hello; { 1 } next if $bar;
      None of those can receive a "statement modifier".

      In fact, if you inspect perly.y you'll see that expressions are modified:

      sideff : error | expr | expr IF expr | expr UNLESS expr | expr WHILE expr | expr UNTIL iexpr | expr FOR expr | expr WHEN expr ;
      with sideff one of the many forms of statements.

      If you're going to reply with irrelevant snobbery, please aim for the middle of the bowl instead of peeing all over the stall.

      And think what exactly is a "statement" in Perl!

        In fact, if you inspect perly.y you'll see that expressions are modified:
        Interesting! Hence, a statement modifier turns an expression in a statement. Didn't expect this.

        BTW, my comment was not intended as snobbery, but because I concluded that statement modifiers are never part of a sub-expression (as the OP wanted to use them). In any case, your comment is appreciated.

        -- 
        Ronald Fischer <ynnor@mm.st>