Re: Global search and replace inside string

2017-03-22 Thread Chris Ramsey
Ah yeah, that would do it then! Thanks so much!

On Wed, Mar 22, 2017, 11:55 AM Brandon Allbery  wrote:

> On Wed, Mar 22, 2017 at 2:50 PM, Chris Ramsey 
> wrote:
>
> my $str = "some string with 'text' in it and more text";
> say $str.subst(/'.*'/, "'m'", :g);
>
> When running this code, I get the original string back, which makes me
> think my regex isn't quite right.
>
> Basically I want to replace anything in single quotes with 'm' (or
> whatever other arbitrary string).
>
>
> In Perl 6 regexes, single quotes actually quote things. So you're telling
> it to look for the literal string ".*".
>
> I think you want something like / "'" .* "'" / (note that spaces are not
> significant in regexes normally).
>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


Re: Global search and replace inside string

2017-03-22 Thread Brandon Allbery
On Wed, Mar 22, 2017 at 2:50 PM, Chris Ramsey  wrote:
>
> my $str = "some string with 'text' in it and more text";
> say $str.subst(/'.*'/, "'m'", :g);
>
> When running this code, I get the original string back, which makes me
> think my regex isn't quite right.
>
> Basically I want to replace anything in single quotes with 'm' (or
> whatever other arbitrary string).
>

In Perl 6 regexes, single quotes actually quote things. So you're telling
it to look for the literal string ".*".

I think you want something like / "'" .* "'" / (note that spaces are not
significant in regexes normally).

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Global search and replace inside string

2017-03-22 Thread Chris Ramsey
Hey all,

I'm working on learning Perl 6 and am trying to write a little utility that
will do a simple search and replace. Could knock this out in a few other
languages quickly, but I really want to get to know Perl 6 better :)

Anyway, so here's some pseudocode that I need some help writing.

my $str = "some string with 'text' in it and more text";
say $str.subst(/'.*'/, "'m'", :g);

When running this code, I get the original string back, which makes me
think my regex isn't quite right.

Basically I want to replace anything in single quotes with 'm' (or whatever
other arbitrary string).

Thanks in advance for any tips!


Re: Am I suppose to be able to change a variable's type on the fly?

2017-03-22 Thread Richard Hainsworth

I think the strict answer to 'Is it correct?' is 'No'.
The point being that 'my $x' gives $x type 'Any'.

But practically, having type Any allows for $x to be assigned any value, 
be it Str, Int etc.


So 'practically' the answer to 'Is it correct?' is 'Yes'.


On Wednesday, March 22, 2017 02:07 PM, Brad Gilbert wrote:

The default type constraint is Mu, with a default of Any (everything
is of type Mu, and most are of type Any)

You shouldn't be able to change the type constraint of a scalar
container (used for rw variables)

Changing the type of a value, of course makes no sense. (a Str is
always a Str, even when you use it as a number)

Basically no you can't change the type, but you didn't do that anyway.

On Wed, Mar 22, 2017 at 12:59 AM, ToddAndMargo  wrote:

Hi All,

Yes, I know, Perl is "lexiconical".

$ perl6 -e 'my $x="abc"; $x=1E23; print "$x\n";'
1e+23

$ perl6 -e 'my Str $x="abc"; $x=1E23; print "$x\n";'
Type check failed in assignment to $x; expected Str
but got Num (1e+23) in block  at -e line 1

So, unless I specifically declare a variable as a
particular type, I can change its "type" on the fly.
Is that correct?


Many thanks,
-T


--
~~~
Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
~~~


Re: Am I suppose to be able to change a variable's type on the fly?

2017-03-22 Thread ToddAndMargo
> On Wed, Mar 22, 2017 at 12:59 AM, ToddAndMargo 
 wrote:

>> Hi All,
>>
>> Yes, I know, Perl is "lexiconical".
>>
>> $ perl6 -e 'my $x="abc"; $x=1E23; print "$x\n";'
>> 1e+23
>>
>> $ perl6 -e 'my Str $x="abc"; $x=1E23; print "$x\n";'
>> Type check failed in assignment to $x; expected Str
>> but got Num (1e+23) in block  at -e line 1
>>
>> So, unless I specifically declare a variable as a
>> particular type, I can change its "type" on the fly.
>> Is that correct?

On 03/21/2017 11:07 PM, Brad Gilbert wrote:

The default type constraint is Mu, with a default of Any (everything
is of type Mu, and most are of type Any)

You shouldn't be able to change the type constraint of a scalar
container (used for rw variables)

Changing the type of a value, of course makes no sense. (a Str is
always a Str, even when you use it as a number)

Basically no you can't change the type, but you didn't do that anyway.




Hi Brad,

That is explains it:

$ perl6 -e 'my Mu $x="abc"; $x=1E23; print "$x\n";'
1e+23

Thank you!

-T

--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: File::Copy ??

2017-03-22 Thread ToddAndMargo
> On Wed, Mar 22, 2017 at 12:24 AM, ToddAndMargo 
 wrote:

>> Hi All,
>>
>> Do we have anything like
>>
>> http://perldoc.perl.org/File/Copy.html
>>
>> under another name?
>>
>> Nothing showed up in
>>https://modules.perl6.org/#q=file%3A%3A
>>
>>
>> Many thanks,
>> -T

On 03/21/2017 10:59 PM, Brad Gilbert wrote:

For basic copy and move, the built-in subs should work

https://docs.perl6.org/routine/copy
https://docs.perl6.org/routine/move




Huh.  Right under my nose.  Thank you!

Have you used copy and move?  Are they top speed
(like cp in Linux or xcopy in Windows) or are
they slow?


Re: Am I suppose to be able to change a variable's type on the fly?

2017-03-22 Thread Brad Gilbert
The default type constraint is Mu, with a default of Any (everything
is of type Mu, and most are of type Any)

You shouldn't be able to change the type constraint of a scalar
container (used for rw variables)

Changing the type of a value, of course makes no sense. (a Str is
always a Str, even when you use it as a number)

Basically no you can't change the type, but you didn't do that anyway.

On Wed, Mar 22, 2017 at 12:59 AM, ToddAndMargo  wrote:
> Hi All,
>
> Yes, I know, Perl is "lexiconical".
>
> $ perl6 -e 'my $x="abc"; $x=1E23; print "$x\n";'
> 1e+23
>
> $ perl6 -e 'my Str $x="abc"; $x=1E23; print "$x\n";'
> Type check failed in assignment to $x; expected Str
> but got Num (1e+23) in block  at -e line 1
>
> So, unless I specifically declare a variable as a
> particular type, I can change its "type" on the fly.
> Is that correct?
>
>
> Many thanks,
> -T
>
>
> --
> ~~~
> Serious error.
> All shortcuts have disappeared.
> Screen. Mind. Both are blank.
> ~~~


Re: File::Copy ??

2017-03-22 Thread Brad Gilbert
For basic copy and move, the built-in subs should work

https://docs.perl6.org/routine/copy
https://docs.perl6.org/routine/move

On Wed, Mar 22, 2017 at 12:24 AM, ToddAndMargo  wrote:
> Hi All,
>
> Do we have anything like
>
> http://perldoc.perl.org/File/Copy.html
>
> under another name?
>
> Nothing showed up in
>https://modules.perl6.org/#q=file%3A%3A
>
>
> Many thanks,
> -T
>
>
> --
> 
> Yesterday it worked.
> Today it is not working.
> Windows is like that.
>