in reply to Perl 6, arrays, hashes, subroutines & basic file IO

2 beginner questions on Perl6.

1. Where is the 'my' in those variable usages?

2. Why did they switch from 'print' to 'say'? It's shorter?


I'm not really a human, but I play one on earth. Cogito ergo sum a bum
  • Comment on Re: Perl 6, arrays, hashes, subroutines & basic file IO

Replies are listed 'Best First'.
Re^2: Perl 6, arrays, hashes, subroutines & basic file IO
by BrowserUk (Patriarch) on Nov 01, 2006 at 13:24 UTC
    1. The only 'variables' I see without my in those snippets are formal parameter names, which are declarative only?
    2. say $var; is equivalent to print $var . $/;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: Perl 6, arrays, hashes, subroutines & basic file IO
by blazar (Canon) on Nov 01, 2006 at 15:43 UTC
    Where is the 'my' in those variable usages?

    As BrowserUk wrote, I don't see any missing. While we're here I'll take a chance to remind that differently from Perl 5, Perl 6 has strict and warnings turned on by default except in particular situations, e.g. in oneliners, where it's most often better otherwise.

    Why did they switch from 'print' to 'say'? It's shorter?

    Err, well, yes: easy things should be easy. And Perl has been somehow missing a writeln/println statement for quite a long time. But as also pointed out by BrowserUk, they did not "switch": you will have both print and say. The interesting thing to note here is that iirc in conjunction with the use of the latter autochomp actions are often taken, although it's not entirely clear to me how and when (I know the answer is out there I'm just too lazy ATM) - but it seems that $_ is not chomped by default:

    pugs> say .chars for <foo bar baz>; 3 3 3 undef pugs> say .chars for =<>; foo 4 bar 4 baz 4