Or, store the string in $_, and take advantage of less to type-

perl6 -e '$_="abc"; say so /z/; say so /b/; s/c/defg/ ?? .say !! say
"Failed!"'


-y

On Tue, Aug 14, 2018 at 4:17 AM, ToddAndMargo <toddandma...@zoho.com> wrote:

> > On 14/08/18 13:08, ToddAndMargo wrote:
> >> Hi All,
> >>
> >> The Perl 5 guys have it pounded into my head that I
> >> always had to check my substitutions to see if they
> >> worked if not working would crash the program.
> >>
> >> So in Perl 6 I have:
> >>
> >> $ p6 'my $x="abc"; if s/b/z/ {say "sub worked"}else{say "sub failed"};
> >> say "$x";'
> >>
> >> Use of uninitialized value of type Any in string context.
> >> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> >> something meaningful.
> >>    in block <unit> at -e line 1
> >> sub failed
> >> abc
> >>
> >>
> >> What am I doing wrong?
> >>
> >> Many thanks,
> >> -T
>
> On 08/14/2018 04:10 AM, Timo Paulssen wrote:
>
>> You're putting your starting string in a variable, $x, but aren't
>> telling the s/// operator specifically what to operate on, so it
>> defaults to $_, which is still at its default value.
>>
>>
>>
> Thank you!
>
> $ p6 'my $x="abc"; if $x ~~ s/b/z/ {say "sub worked"}else{say "sub
> failed"}; say "$x";'
> sub worked
> azc
>
> $ p6 'my $x="abc"; if $x ~~ s/x/z/ {say "sub worked"}else{say "sub
> failed"}; say "$x";'
> sub failed
> abc
>

Reply via email to