> On Apr 2, 2025, at 05:47, ToddAndMargo via perl6-users <perl6-users@perl.org> 
> wrote:

--snip--

> Hi Bruce,
> 
> Sorry.  I do know I am suppose to post some minimal code.
> I was programming for 11 straight hours and was not
> thinking too clearly.

I understand.

> I was trying to do what you said.  Read it into a hash, then
> extract the values into an OOP structure.    (I use to like
> hashes, but dropped them hard when I figured out OOP
> structures.  I absolutely  A-D-O-R-E  OOP structures.)
> 
> Thank you again for the help!
> -T

--snip--


> my $CommandLine = CommandLineClass.new{
>    help           => False,
>    debug          => False,
>    UNC_BackupPath => Q[\\192.168.240.10\MyDocsBackup\backup1],
>    rotates        => 2,
>    ParentDir      => "/"
> };

The problem is with the syntax of the `new`.
You need parenthesis instead of curly braces.
With that change, your code works as expected.

For even DRYer code, you can flatten `%opts` directly into the `new` 
constructor, like so:
    # use lib 'C:/NtUtil', 'C:/NtUtil/p6lib';   # use this one on customer 
machines
    use Getopt::Long;
    class CommandLineClass is rw {
        has Bool $.help           = False;
        has Bool $.debug          = False;
        has Str  $.UNC_BackupPath = Q[\\192.168.240.10\MyDocsBackup\backup1];
        has Int  $.rotates        = 2;
        has      $.ParentDir      = '/';
    }
    my %opts = get-options( 'help', 'debug', 'UNC_BackupPath=s', 'rotates=i', 
'ParentDir=s' ).hash;
    my CommandLineClass $CommandLine .= new( |%opts );
    say $CommandLine.raku if $CommandLine.debug;

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks)

Reply via email to