develooper Front page | perl.perl6.language | Postings from May 2004

Re: C style conditional statements

Thread Previous | Thread Next
From:
Juerd
Date:
May 12, 2004 11:15
Subject:
Re: C style conditional statements
Message ID:
20040512181536.GT22255@c4.convolution.nl
Aaron Sherman skribis 2004-05-12 14:04 (-0400):
> Perl 5:
>         #!/usr/bin/perl
>         while(<>) {
>         	s/\w+/WORD/g;
>         	print;
>         }
> Perl 6:
>         #!/usr/bin/perl
>         while $stdin.getline -> $_ {

Empty <> uses ARGV, not STDIN. It only uses STDIN if not @ARGV (or if
'-' is in @ARGV).

>         	s:g/\w+/WORD/;
>         	$stdout.print;

A2 says $*STDIN and $*STDOUT. Has this been changed?

Also, will there no longer be the concept of a selected filehandle? I'd
hate to have to specify stdin and stdout in throw away scripts.

>         }

I think I like this better:

    for <> {
        s:g/\w+/WORD/;
        print;
    }

But I think I still want to have some non-mutating version of s/// that
returns the modified string, so that you can just write something like

    print s:gx/\w+/WORD/ for <>;


Juerd

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About