Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

  • (Sep 10, 2018 at 22:53 UTC) Welcome new users!
If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
How to serialize and deserialize Dios/Object::InsideOut objects?
1 direct reply — Read more / Contribute
by clueless newbie
on May 23, 2019 at 14:51


    I'm struggling with serializing and deserializing Dios/Object::InsideOut objects. So far as I can tell Dios makes use of Object::InsideOut and Object::InsideOut provides $object->dump() and Object::InsideOut->pump() for serialization/deserialization. On an object that does NOT contain another object I've been able to get it to work but when the object contains other objects as in the code below nothing I've tried works?

    #!/usr/bin/env perl use Data::Dumper; use Data::Dx; use Dios { accessors => 'unified' }; use Getopt::Long; use Path::Tiny; use Test::Expr; use 5.014_00; class Nada { has Int $.number is rw; }; class Yada { has Int $.number is rw; has Nada @.nadas is rw; }; # class Yada: BEGIN { # Let's confirm that Dios uses Object::InsideOut so we can "dump" +and "pump" say $INC{'Object/'}; }; Getopt::Long::GetOptions( "initialize" => \my $initialize, "restore" => \my $restore, "save" => \my $save, ); say "<co de>"; Nada->new(), Yada->new(), say "initialized!" if ($initialize); sub test_our_yada { my $self=shift; ok $self->isa('Yada'); ok $self->number() == 0; ok @{$self->nadas()} == 2; Dx $self->nadas(); ok $self->nadas()->[0]->number() == 1; ok $self->nadas()->[1]->number() == 2; } if ($save) { # The "initial" Yada my $yada=Yada->new(number=>0,nadas=>[Nada->new(number=>1),Nada->ne +w(number=>2)]); $yada->main::test_our_yada(); # $erialized and written to 'Yada.dat' Path::Tiny::path('Yada.dat')->spew_raw($yada->dump(1)); done_testing; } elsif ($restore) { # The restored from 'Yada.dat' Yada my $yada=Object::InsideOut->pump(Path::Tiny::path('Yada.dat')->slu +rp_raw()); $yada->main::test_our_yada(); done_testing; } else { warn "Needs a 'save' or a 'restore'."; } say "</co de>"; __END__
    My results can be seen

    What am I doing wrong - and how do I fix it?

Why do I need a local variable in map function
1 direct reply — Read more / Contribute
by Anonymous Monk
on May 23, 2019 at 03:31

    Hi Monks,

    I have a function with should select files by a given list of extension. I wrote a program, which did not work. After playing a little around I found a working solution (using a local variable: my $x). But I do not understand, why my first version is not working.

    Can you help me explaining the difference between this two versions:

    In the first version the expression(@ext) is replaces by '1';

    In the second version the expression(@ext) is correct. ('f.*\\.txt$', 'f.*\\.txt.*$')

    Thanks for your help !!!

    use strict; use warnings; use Data::Dumper qw(Dumper); $\="\n"; my @ext; my @list=('f1.txt','f2.txtx','f3.xtxt','x1.txt'); my $ex="f*.txt,f*.txt*"; print " Version 1: Not working--------------------------------"; @ext=map { $_=quotemeta($_).'$'; s/\\\*/.*/;} split(/,/,$ex); + # <<<<<< compare this line print "qr=".Dumper(\@ext); foreach my $e(@ext) { foreach my $f(@list) {print "Match: ($e) => $f" if ($f=~m/$e/); }} print " Version 2: working--------------------------------"; @ext=map { my $x=quotemeta($_).'$'; $x=~s/\\\*/.*/g; $_=$x;} split(/,/ +,$ex); # <<<<<< compare this line print "qr=".Dumper(\@ext); foreach my $e(@ext) { foreach my $f(@list) {print "Match: ($e) => $f" if ($f=~m/$e/); }}
Config::General to read both scalars and arrays
2 direct replies — Read more / Contribute
by The_Marshall
on May 22, 2019 at 11:57

    Hey all,

    In a nutshell, I'm trying to accomplish the following:

    # config.ini include default.ini user_name = "Marshall" # Change value within default.ini list_of_items = ["apple", "ball", "cup"]

    However, what I wind up with are 2 scalars:

    { 'user_name' => 'Marshall', 'list_of_items' => '["apple", "ball", "cup"]' }

    I've tried so many different settings. The above generated with:

    ParseConfig( -ConfigFile => 'simple.ini', -UseApacheInclude => 1, -MergeDuplicateOptions => 1 );

    So, I need some advice. I've even tried to use blocks to hold arrays, but nothing seems to work.

    Config::General::Version = '2.63'

Tracking and deploying changes in (MySql/Maria) DB schema ...
3 direct replies — Read more / Contribute
by LanX
on May 22, 2019 at 11:56

    Looking for inspiration ...

    Are there recommended solutions to track and replicate changes on MariaDB tables?

    I was hoping that DBs like information_schema or mysql might log ALTER TABLE queries.

    My research pointed me to 'log_bin':

    find the binary log for the relevant time period, use mysqlbinlog to convert it to SQL, then grep for the relevant table name to find the alter table statement

    I'd be interested to know about alternatives.


    My client likes to change from time to time the data model for some of my applications and tends to inform me per email "Please change ..." afterwards.

    To make it more difficult this models are used on several different DB Severs.

    My application is already adapting to the local model on a server and checking the schema against a "master" server, but I'd like to have better control and allow a semi-automatic update.

    A manual solution would be to train my client to record every ALTER TABLE manually after changes

    ... well ... I'm not too keen for the resulting social tension of enforcing protocols.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Does perl read the entire pl file into memory?
5 direct replies — Read more / Contribute
by harangzsolt33
on May 21, 2019 at 11:21
    I have thought about putting a large comment section into my perl script after the __END__ mark, and I am wondering if this is okay. How does perl parse the files? Does it read the entire script into memory FIRST even if it's over 1MB, or does it read pl files one buffer at a time and when it encounters the __END__ then it stops reading? If it reads the entire script into memory, then I guess it would be wiser for me to put the comments into a separate text file..
Using a factory class to return objects of the same class
2 direct replies — Read more / Contribute
by Amblikai
on May 21, 2019 at 10:35

    Hi Monks!

    I have a question which might be considered a "stylistic" issue but i thought i would get some insight.

    Essentially i have a class which requires some configuration (read an XML file to decide how to handle incoming data)

    Lots of objects are then created of that class using a data structure which can be fairly arbitrary

    So basically, i'm musing over the problem of seperating the incoming data with configuration options. Something like

    my $obj=class->new({config_file => "file.xml", data => \%some_yummy_da +ta});

    Which doesn't seem very elegant to me. So i was thinking of handling it slightly differently:

    my $factory=class->new({config_file => "file.xml"}); my $obj=$factory->give_me_my_object(\%data);

    But then THAT seems weird since its essentially a factory returning objects of it's own class. And on top of that, it raises questions like what would happen if i tried to access "factory only" methods through the produced objects etc.

    Any thoughts? Am i over complicating this?

    Thanks as always for any help!

Modernizing a Deploy script to standard distro v5.10.1
5 direct replies — Read more / Contribute
by rje
on May 20, 2019 at 10:58

    Good morning fellow monks.

    On purpose, I volunteered to update a deploy script. The current script is a Perl 4 stand-alone script that copies files into their proper deployment locations.

    How you would do this?

    I sold my boss on moving common code into a package, because it would (1) hide and reuse duplicated code, (2) shorten new typical deploy scripts dramatically; (3) potentially reduce accidental errors, (4) introduce such innovations as use strict; and use warnings; and (5) give the systems team a tiny bit of control over code maintainability, as opposed to 'no control' today.

    CONSTRAINT: I'm limited to the standard distribution for v5.10.1. I can't install packages.

    I'm thinking of a package that minimizes the "visual change" of the existing way, but adds a healthy dose of SAFER.

    Here's a very typical example. Note the lack of safe practices.

New Meditations
git-push target for Makefile (via ExtUtils::MakeMaker)
No replies — Read more | Post response
by bliako
on May 21, 2019 at 09:22

    I was trying to automate more (=keep as far away as possible) the process of pushing to github through a Makefile and I came up with the following simplistic approach. It basically creates a make target called git-push via MY::postamble provided by ExtUtils::MakeMaker. I got the postamble idea from pryrt's answer to Benchmarks target in Makefile

    perl Makefile.PL make all make git-push

    At first it creates a .gitignore file which whitelists the files/dirs to push, then calls git init, git add ., git commit ... and finally git push ... (I hope it's correct, it works for me).

    As it is, it works for me but I am sure there are lots and lots of improvements and safeguards. Also, it does not proceed unless the target repository already exists remotely - there is no git-cmdline-only way to create a repository as I understand.

    Possible major improvement would be to use Git::Repository instead of make shelling out git commands. But this is the idea I wanted to share.

    Deviations from the normal Makefile.PL are designated by ADD this:

    bw, bliako

New Monk Discussion
Something changed the creation time/date of all my posts?
3 direct replies — Read more / Contribute
by BrowserUk
on May 22, 2019 at 04:11

    As this image shows, sometime over the last few days, the listed "creation time", and sometimes date also, of all my posts has changed.

    No big deal, but ...

    1. Is management aware of it?
    2. Is it deliberate?
    3. Is there a (good?) reason for it?

    No urgency, but nice to know.

    Also, how does management view/process "Rights to Erasure" under GDPR?

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2019-05-26 19:28 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (153 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!