If you've discovered something amazing about Perl that you just need to share with everyone, this is the right place.

This section is also used for non-question discussions about Perl, and for any discussions that are not specifically programming related. For example, if you want to share or discuss opinions on hacker culture, the job market, or Perl 6 development, this is the place. (Note, however, that discussions about the PerlMonks web site belong in PerlMonks Discussion.)

Meditations is sometimes used as a sounding-board — a place to post initial drafts of perl tutorials, code modules, book reviews, articles, quizzes, etc. — so that the author can benefit from the collective insight of the monks before publishing the finished item to its proper place (be it Tutorials, Cool Uses for Perl, Reviews, or whatever). If you do this, it is generally considered appropriate to prefix your node title with "RFC:" (for "request for comments").

User Meditations
Role Composition versus Inheritance
1 direct reply — Read more / Contribute
by choroba
on Feb 07, 2016 at 15:37
    I use Moo in my latest toy project. When experimenting with Moo::Role, I discovered the rules of interaction of role composition and inheritance are not specified in detail, and the current behaviour surprised me a bit.

    In the examples below, I'll use Role::Tiny, as that's what Moo::Role uses under the hood, and it also contains all the important documentation.

    The basic rule of role composition is the following:

    If a method is already defined on a class, that method will not be composed in from the role.

    Let's see an example:

    #! /usr/bin/perl use warnings; use strict; use feature qw{ say }; { package MyRole; use Role::Tiny; sub where { 'Role' } sub role { 'yes' } } { package MyClass; sub new { bless {}, shift } sub where { 'Class' } } { package MyComposed; use Role::Tiny::With; with 'MyRole'; sub new { bless {}, shift } sub where { 'Composed' } } my $c = 'MyComposed'->new; say $c->$_ for qw( where role );


    Composed yes

    The "yes" shows the role was composed into the class, but the "where" method still comes from the original class. So far, so good.

    What do you think should happen, if the class doesn't implement the method, but inherits it from a parent?

    { package MyHeir; use parent -norequire => 'MyClass'; use Role::Tiny::With; with 'MyRole'; } my $h = 'MyHeir'->new; say $h->$_ for qw( where role );

    For me, the output was surprising:

    Role yes

    The same happens when you apply the role to an instance of a class:

    my $o = 'MyClass'->new; 'Role::Tiny'->apply_roles_to_object($o, 'MyRole'); say $o->$_ for qw( where role );

    We started with an object of a class that implemented the where method, but the resulting object uses the role's method. Maybe because a new class is created for the object inheriting from the original one, and the role is then applied to it, as with MyHeir above?

    In fact, I needed that behaviour. As it's not documented explicitely, though, I decided to program defensively, require the where method, and use the around modifier for better readability and clearer specification of the intent:

    { package MyAround; use Role::Tiny; requires 'where'; around where => sub { 'Around' }; sub role { 'yes' } } my $o2 = 'MyClass'->new; 'Role::Tiny'->apply_roles_to_object($o2, 'MyAround'); say $o2->$_ for qw( where role );

    Even if the composition rules changed, my object would still get the where method from the role.

    Update: I proposed a documentation fix that was later accepted.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Focussing Haskell into Perl 6
1 direct reply — Read more / Contribute
by drforr
on Feb 03, 2016 at 06:42
    On the bus ride out to Charleroi I caught a stray brainwave about how to properly notate at least some of Haskell's Lens library, so I wrote up some notes on it. This is going to be slightly spooky, but not much more than the previously-existing ability to bind one data structure to another. I don't know if this is in the spirit of the Haskell library, as it relies heavily on types and type transformations, but I gather that types don't perform quite the role they do in Perl 6. We could conceivably make the lens type-aware so that a lot of mechanism could go away, but the code below has the general idea. The 'lens' library is essentially a metaphor for focussing in on your data, in roughly the following sense:
    my $lens = Optical::Bench::BeamSplitter.new; $a =< $lens >= $b; # Think of $a "passing through" $lens into $b. $a = 'foo bar'; is-deeply $b, [ 'foo', 'bar' ]; $b.[1] = 'moo'; is $a, 'foo moo';
    Lenses can be chained:
    my $lens2 = Optical::Bench::BeamSplitter.new('-'); $a =< $lens >=< $lens2 >= $b; $a = 'foo-bar baz-qux'; is-deeply $b, [ [ 'foo', 'bar' ], [ 'baz', 'qux' ] ];
    If that behavior is a little too magical, use the '<<' and/or '>>', and then the changes only go in one direction, or none at all (but they'll still happen on binding.)
    $a << $lens >= $b; $a = 'foo bar'; is-deeply $b, [ 'foo', 'bar' ]; # ok 1 $b.[0] = 'moo'; is-deeply $b, [ 'moo', 'bar' ]; is $a, 'foo bar'; # ok + 2, ok 3
    If you're having trouble coming up with a use for this, envision database work, where you have a transform (like, say, converting timestamps) you need to do on the way in and out of the database:
    my $lens = O::B::mySQL.new('Mmm dd, yyy'); $created-date =< $lens >= $created-date-mySQL; is $created-date, 'Feb 3, 2016'; is $created-date-mySQL, '2016-02-03T09:50+02:00';
    Put this anywhere in your method, and you can rest assured that the mySQL date will be formatted correctly when it gets saved. With sufficient black magic, it might even work like:
    $post.<created-date> =< O::B::mySQL::Date.new >= $params.<created>;
    so you could drop that into your Dancer'ish Controller, or maybe even directly in your database Model, once there's an ORM thing for Perl 6.
Introducing Scheme In Perl 6
1 direct reply — Read more / Contribute
by drforr
on Jan 26, 2016 at 02:52
    Where it is right now:
    use Inline::Guile; my $g = Inline::Guile.new; say $g.run_i('(+ 3 7)'); # 10 say $g.run_s('"boo"'); # 'boo'
    Where it will go soon:
    say $g.run('(+ 3 7)'); say $g.run('"boo"');
    After Slang::Guile has been written:
    use Slang::Guile; guile-sub car( $x ) { car $x } guile-sub cdr( $x ) { cdr $x } use Test; is car <a b c>, 'a'; is-deeply [ cdr <a b c> ], ['b', 'c'];
    I've already figured out how to write the helper code for most of this. Writing the C glue code at compile time using Perl 6 will let me share constants between C, Guile and Perl 6. Two problems I can foresee with this are that strings will need to be surrounded with dynwind-protect so that they don't leak from the Guile interpreter, and I don't think the NativeCall array types support arbitrarily-recursive arrays, I.E. CArrayInt is just a flat array of entries. I can solve this by passing back a typed array of int32s like so:
    (3 "a" (7 9) "after") => ( INTEGER, 3, STRING, "a", START-LIST, Nil, INTEGER, 7, INTEGER, 9, EN +D-LIST, Nil, STRING, "after" )
    so that everything is returned in a homogeneous data structure, and it's up to the Perl 6 layer to unswizzle this back to:
    is-deeply \$g.run(q{'(3 "a" (7 9) "after")}), [ 3, "a", [ 7, 9 ], "after" ];
    Hopefully I'll have time around FOSDEM to put this all together.
hard versus soft reference to ARRAY's
3 direct replies — Read more / Contribute
by teun-arno
on Jan 24, 2016 at 16:56

    Was playing with splice and noticed that there is a difference between hardcoded ARRAY refenrences and softcoded ARRAY references. Hope this will help somebody in future!! See also : http://perlmaven.com/splice-to-slice-and-dice-arrays-in-perl. Please notice : I've changed the code from the above link.

    $dwarfs = [ qw(Doc Grumpy Happy Sleepy Sneezy Dopey Bashful) ]; print "@{$dwarfs}\n"; print "@dwarfs\n"; @removed = splice @{$dwarfs},3 ,2; $removed = [ @removed ]; #1. please notice : this makes a copy first +of @removed . # changes to @{$removed} will NOT affect @removed #$removed = \@removed ; #2. please notice : this is a hard reference + . # changes to @{$removed} will affect @removed. # let's examine the above : Just uncomment one of the above lines # it's you're choise which one to use. pop @{$removed} ; print "@removed\n";

    greetings Arno Teunisse

Bug in eval in pre-5.14
4 direct replies — Read more / Contribute
by choroba
on Jan 23, 2016 at 11:45
    For some reason, the following pattern is still used in code - I've seen it at a recent interview and in an accepted answer at Stack Overflow.
    eval { # code that could die }; if ($@) { # Poor man's catch!

    On pre-5.14 Perls, this is a bug. Sometimes, the code inside the eval could die, but the catch wouldn't be triggered, because the $@ could be clobbered - see perl5140delta for details. If you want to use modules from other people, there's no way how to prevent the bug. If the foreign code calls eval in an object's destructor, you're doomed.

    Fortunately, it's rather easy to improve the pattern:

    eval { # code that could die; 1 } or do {

    That way, you can really detect the failure in the "try" block, even if the exception could get lost.

    Here's a simple example that demonstrates the problem. Note that Try::Tiny doesn't provide more than the "or do" pattern:

    #!/usr/bin/perl use warnings; use strict; print $], "\n"; { package My::Obj; sub new { my $class = shift; bless {@_}, $class } sub DESTROY { my $self = shift; eval { 1 } if ! $self->{finished}; } } my $o1 = 'My::Obj'->new(finished => 1); undef $o1; # Exception overlooked. eval { my $o2 = 'My::Obj'->new; die "Exception!"; }; if ($@) { warn "Caught with \$\@: $@"; } # Exception details lost. eval { my $o2 = 'My::Obj'->new; die "Exception!"; 1 } or do { warn "Caught with or: $@"; }; # Same as above. use Try::Tiny; try { my $o3 = 'My::Obj'->new; die "Exception!"; } catch { warn "Caught with Try::Tiny: $_"; };

    In 5.20, I'm getting:

    5.020001 Caught with $@: Exception! at ./eval.pl line 25. Caught with or: Exception! at ./eval.pl line 34. Caught with Try::Tiny: Exception! at ./eval.pl line 44.

    But, in 5.12, the first exception gets overlooked. The second syntax at least notices something went wrong, but the exception is lost anyway.

    5.012005 Caught with or: at eval.pl line 36. Caught with Try::Tiny: at eval.pl line 46.
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
RFC: The lightning-rod operator
3 direct replies — Read more / Contribute
by martin
on Jan 22, 2016 at 11:32

    "It's not as if it's a particularly nice house," [Mr. Prosser] said.
    "I'm sorry, but I happen to like it."
    "You'll like the bypass."

    — Douglas Adams, The Hitch-Hikers Guide to the Galaxy

    The Stage

    Extending the Perl 5 language is not to be taken lightly. After more than two decades of stable releases, most basic design decisions have been settled and there is quite some evidence of the language being useful as it is.

    Still, if a new feature promises benefit, is documented well, can't easily be covered by a module, is implemented by someone, does not break backwards compatibility, nor the stability or efficiency of the compiler, and comes with an agreeable syntax, Perl 5 Porters might be inclined to accept it. This can happen. Occasionally.

    I'd like to find out what other Perl monks think about this new operator I have been fantasizing about.

About the CORE and the history of Module::Pluggable
2 direct replies — Read more / Contribute
by Discipulus
on Jan 18, 2016 at 06:54
    hello monks,

    The preamble to this post must be clear: i'm four year late and i do not want to criticize Perl devs who maintain and make perl a better thing with new releases, i want just to know what happened and why.

    The fact: i was lurking on the web with some vague perl learning intention when i came across Module::Pluggable in the official perl docs and I was intrigued by it.
    After a while, since i've closed the browser tab, I've gone for it in the modules (M) list the official docs and i was surprised to not find it there. I've lazyly asked in the chat with no luck.
    Put aside my lazyness i searched the possible motivation and i found this post that announced the module to be removed from core prior the 5.20 Perl release.

    Then, picking up a little of hubrys, i decided to know why it had to be removed, searching (as suggested by tye) the p5p archive and i found
    module deprecations for 5.18 by Ricardo Signes listing all candidates to be removed from 5.18.
    The post mention at the beginning that the original discussion was started by Sayer X at Taking CPANPLUS out of core

    Now i've read them all and i 've understood something: the goal was to remove CPANPLUS (i assume it is problematic or bugged or not so used..).
    A dependency scan of modules used by CPANPLUS was made and for these modules other core modules were searched using them to be sure nothing important would be removed. The list contains Module::Pluggable.

    While reading these long threads i read this good sentence by Steffen Muller I want to report (because i was in the 'many' count below..):
    I think in all of this, choice of words was a bit poor. "Deprecated" will read to many as "don't use, it's bad", whereas it just means "won't be in core in the future". Please make really, really, really sure this is clear to everyone.

    Understood this concept I still do not understand why to remove Module::Pluggable from core.

    My idea of the core may be wrong but i think it is convenient (from the users perspective, not the devs) to have many useful modules in it.
    It is not a problem installing from CPAN (Yes, even you can use CPAN) but i ever look to core modules as the minimal common factor every perl users can have.
    A Perl's program that uses only core modules has anyway a plus in my mind. Also in my limited perl playground i've enough machines to be tired to install too many CPAN modules if i can write down my scripts using core modules. This does not means that i reinvent every wheel i come across, so if i need something to process, let's say, hairy XML i'll install XML::Twig with no problem. But i dont install (as for a recent example) DateTime::Format:: Strptime just to do a one-time time string conversion.

    It sounds so ureasonable my opinion? Personally i'd like many others things in core: many *::tiny modules are candicates in my mind. Considering th above example of XML, would not be better to have XML::Twig (or similar good ones) in the core, istead of having all XML new comers been fooled for weeks by the XML::Simple siren?
    Probably i would like too many things in the core (Tk..) but why to remove unharmful modules? or is somehow Module::Pluggable risky and i've not found right infos?

    Incidentally i learned something useful: declare dependencies also for core modules because nothing is eternal!

    About Module::Pluggable i was intrigued by it and i was considering to add the plugin ability to one of my long running spare time projects. Also the module had very good reviews also from one of the author of the mentioned p5p posts (ok was 2007..). the module was also put into the Perl Advent Calendar (ok was in the 2004..). So why it was removed?


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
RFC: Text::Quote::Self - A context-based self-quoting facade for unsafe strings
1 direct reply — Read more / Contribute
by Dallaylaen
on Jan 18, 2016 at 04:19

    Hello fellow monks,

    Following up my own question in SOPW, I would like to release a module implementing the following concept.


    use Text::Quote::Self qw(quote_text); my $safe = quote_text($user_input); # create a magic string object $safe = Text::Quote::Self->new($user_input); # ditto say $safe; # input as is say $safe->as_uri; # uri-encoded $safe =~ s/foo/bar/; # changes original, permanently my $data = { text => $safe }; # elsewhere in the app say JSON::XS->new->allow_blessed->convert_blessed->encode($data); #text as is local $Text::Quote::Self::Style = "as_html"; say $data->{text}; # now with entities # or in a Template You were searching for <a href="/search?q=[% search_term.as_uri %]">[% search_term %]</a>.

    The concept

    Say we have an application that produces convoluted data structure which can be presented in multi[ple ways (who said MVC?). Now depending on the presentation, some strings may need to be escaped/quoted, e.g. if we form an HTML document, we'll have to use HTML entities for some characters; but if we send it via JSON, no quoting is needed.

    To encode such strings properly, we have to either know what presentation is to be used and pre-encode the strings in the data layer, or know which strings are safe and which aren't in the presentation layer. This breaks encapsulation of presentation and data, respectively.

    Now my proposed solution is to create an object with overloaded stringify operation and a set of quoting methods. The preferred method is then chosen based on a package variable. This allows to localize choice to a scope, e.g. set to HTML during template processing subroutine.

    The questions

    • is Text::Quote::Self a descriptive enough name? Is Text the right namespace?
    • is quote_text a descriptive enough name? How likely it is to infringe on a user's sub name?
    • I noticed that in my own project where this concept first appeared quote_text and decode_utf8 often come together. Would it be a good idea to add a switch to auto-encode non-utf strings during construction?
    • local $Foo::Bar looks oldish. Maybe an alternative based on guard objects should be used? Exporting the magic variable didn't work for me.

    Whatever is done so far is available on github.

RFC: Continuous Integration (CI) for your CPAN modules (for free!)
3 direct replies — Read more / Contribute
by stevieb
on Jan 15, 2016 at 11:31

    This guide will attempt to explain the basics of using a version control system (specifically GitHub), along with other free online tools to automate your builds and generate test coverage reports automatically on each update to your code.

    It'll be a work in progress for some time (very high level overview at this time), so feel free to leave comments for fixes/updates etc. This doc assumes that you already have module code you've written (eg: My::Module). There's a fair amount of detail lacking because I can't remember the exact steps for everything, but over the weekend, I'll re-run the entire process and fill in the large gaps here.

    First, head on over to GitHub, and sign up for a free account, and create a repository (eg: my-module).

    Now, install git, and clone your newly created (empty) repo to the local machine:

    git clone https://github.com/username/my-module

    From the directory above your actual module code, copy the contents of the module's top level dir into the new empty repo dir:

    cp -R My-Module/* my-module

    Add these files to git, and perform your first check-in:

    cd my-module git add . git commit -am "initial import" git push

    You now have revision control for every change you make going forward to your module.

    Next, head over to Travis-CI, and sign up for an account with your GitHub username. After signed in, 'sync' your account to github, and in your repositories screen, you'll see an on/off toggle for your new repository. Enable it.

    Now go to Coveralls and perform the same task you did for Travis.

    At this point, everything should be enabled and ready for use. To proceed, you'll need to set up a .travis.yml file in your distribution's root directory. Here's one that I use in all of my modules. It's configured to run the build on perl versions 5.8 through 5.22, and it'll also perform test coverage in prep for sending to Coveralls.

    language: perl perl: - "5.22" - "5.20" - "5.18" - "5.16" - "5.14" - "5.12" - "5.10" - "5.8" os: - linux before_install: - git clone git://github.com/travis-perl/helpers ~/travis-perl-helpe +rs - source ~/travis-perl-helpers/init - build-perl - perl -V - build-dist - cd $BUILD_DIR install: - cpan-install Devel::Cover - cpan-install --deps - cpan-install --coverage before_script: - coverage-setup script: - PERL5OPT=-MDevel::Cover=-coverage,statement,branch,condition,path, +subroutine prove -lrv t - cover after_success: - cover -report coveralls - coverage-report matrix: include: - perl: 5.20 env: COVERAGE=1

    Note that Travis doesn't do testing on Windows, so I always advise having a Windows machine/VM handy, and run your test suite on there to ensure it runs cross-platform (if necessary) before upload to CPAN.

    Perform a change in your code, then commit and push it to GitHub. Now go to your Travis page (mine's https://travis-ci.org/stevieb9/ for example), and your build should be running or just about to start.

    If all builds succeed, head on over to your Coveralls page (eg: https://coveralls.io/github/stevieb9/), and you should see a page with your repos listed, with the coverage details of your unit tests.

    Click on the repository, and at the top of the page, click "Badge URLs". Copy the entire text that contains the HTML link. You'll need this, along with a Travis link for your repo to add to your POD documentation.

    *Note*: I can't remember where I got my own Travis link from, but yours will be the same as mine, simply replace the name of my repo with yours. See the example below...

    Now, in your POD, add a tiny bit of markup and paste in your new links. I put mine in the NAME section so it's visible immediately to visitors to my modules on CPAN:

    =head1 NAME Devel::Examine::Subs - Get info about, search/replace and inject code +into Perl files and subs. =for html <a href="http://travis-ci.org/stevieb9/devel-examine-subs"><img src="h +ttps://secure.travis-ci.org/stevieb9/devel-examine-subs.png"/> <a href='https://coveralls.io/github/stevieb9/devel-examine-subs?branc +h=master'><img src='https://coveralls.io/repos/stevieb9/devel-examine +-subs/badge.svg?branch=master&service=github' alt='Coverage Status' / +></a>

    This will result in two images in the NAME section of your POD when users view your module on CPAN. One will show the build success or fail, the other the percentage of test coverage you have.

    Here's an example of what this looks like. You can click through both images and get to the full details of both the build process, and the coverage results.


    • - coveralls.io only does line testing, so I always use Devel::Cover in conjunction to get even more detailed coverage
RFC: Installing DBD::Oracle on Mac 'el capitaine"
No replies — Read more | Post response
by Sandy
on Jan 14, 2016 at 16:09

    There are some specific issues with the new Mac operating system and oracle client. The information is 'out there' on-line, but the information is not all in one place.

    This is my tutorial on how to install DBD::Oracle. I make no claims that it is the 'only' way, but I checked (and double checked) and it seems to work.

    If it meets your exacting standards, I would like to move this to the tutorial section

    Installing DBD::Oracle on Mac (El Capitaine).

    I had a few issues when installing DBD::Oracle on El Capitaine, but eventually succeeded. I thought I would share my process, which may help someone attempting the same process.

    PS: I didn't figure this out all by myself, I would like to give credit to the blogs/tutorials listed in the reference section below


    1. Get Oracle client
      • download from: http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
        • instantclient-basic-macos.x64-
        • instantclient-sdk-macos.x64-
        • instantclient-sqlplus-macos.x64-
    2. Install Oracle client
      • Create directory /Library/Oracle
      • copy previously installed zip files to this directory
      • unzip files
        cd /Library sudo mkdir Oracle sudo cp ~/Downloads/instantclient*.zip . sudo unzip instantclient-basic-macos.x64- sudo unzip instantclient-sdk-macos.x64- sudo unzip instantclient-sqlplus-macos.x64-
    3. Configure Oracle client
      • Create a /network/admin folder in instantclient_11_2
      • cd instantclient_11_2 sudo mkdir network sudo mkdir network/admin
      • Using a text editor, create tnsnames.ora in the network/admin folder
      • Be sure to replace hostname and SID with the appropriate data for your Oracle instance. network/admin folder. It should contain:
      • set environment variables. Edit ~/.bash_profile and add the following
      • ORACLE_HOME=/Library/Oracle/instantclient_11_2 DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Library/Oracle/instantclient_11_ +2 TNS_ADMIN=/Library/Oracle/instantclient_11_2/network/admin PATH=$PATH:/Library/Oracle/instantclient_11_2 CLASSPATH=$CLASSPATH:$ORACLE_HOME export ORACLE_HOME export DYLD_LIBRARY_PATH export TNS_ADMIN export PATH export CLASSPATH
      • or edit ~/.tcshrc (I don't use bash... :( )
      • # required for the Oracle Client setenv ORACLE_HOME /Library/Oracle/instantclient_11_2 if ($?DYLD_LIBRARY_PATH) then setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:$ORACLE_HOME else setenv DYLD_LIBRARY_PATH $ORACLE_HOME endif setenv TNS_ADMIN $ORACLE_HOME/network/admin setenv PATH ${PATH}:$ORACLE_HOME if ($?CLASSPATH) then setenv CLASSPATH ${CLASSPATH}:$ORACLE_HOME else setenv CLASSPATH $ORACLE_HOME endif
      • source your .bash_profile or .tcshrc file, or log off and then back on.

    4. Test Oracle Client
      • If this works, great!
      • [~] sqlplus -v SQL*Plus: Release Production [~]
      • If you get this error message,...
        dyld: Library not loaded: /ade/dosulliv_sqlplus_mac/oracle/sqlplus/lib +/libsqlplus.dylib Referenced from: /Users/sandy/Downloads/instantclient_11_2/sqlplus Reason: image not found
        then the DYLD_LIBRARY_PATH has not been set properly.
    5. Install DBD::DBI
    6. [~] sudo cpan Password: Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v2.00) Enter 'h' for help. cpan[1]> install DBI

    Installing DBD::Oracle

    I had issues with this, so I did not use CPAN.

    1. Prepare:
      • download the tarball for DBD::Oracle


      • unzip and untar
        gunzip DBD-Oracle-1.75_2.tar.gz tar -xvf DBD-Oracle-1.75_2.tar cd DBD-Oracle-1.75_2
    2. prepare the make file:
      [~/Downloads/DBD-Oracle-1.75_2] perl Makefile.PL [... deleted stuff ...] Using DBI 1.634 (for perl 5.018002 on darwin-thread-multi-2level) inst +alled in /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBI/ Configuring DBD::Oracle for perl 5.018002 on darwin (darwin-thread-mul +ti-2level) [... deleted stuff...] Installing on a darwin, Ver#15.0 Using Oracle in /Library/Oracle/instantclient_11_2 dyld: Library not loaded: /ade/dosulliv_sqlplus_mac/oracle/sqlplus/lib +/libsqlplus.dylib Referenced from: /Library/Oracle/instantclient_11_2/sqlplus Reason: image not found [... more deleted errors ...]
    3. Fixing dyld: Library not loaded: problem

      For some reason, the DYLD_LIBRARY_PATH environment variable is not being used/set correctly? (even though 'sqlplus' works)

      1. create a bash script with this content named "fix_dyld.sh". (see reference 4 below for link to article which explains what this is doing)
        • Note that this is modified from what was shown in the reference 4 because "el capitaine" does not like "@executable_path". I changed to code to hardcode the paths to "/Library/Oracle/instant_client_11_2"
        #!/bin/sh # script to change the dynamic lib paths and ids for oracle instant cl +ient # exes and libs # proces all the executable files in this directory find . -maxdepth 1 -type f \( -perm -1 -o \( -perm -10 -o -perm -100 \ +) \) -print | while read exe do echo echo adjusting executable $exe baseexe=`basename $exe` otool -L $exe | awk '/oracle/ {print $1}' | while read lib do echo adjusting lib $lib baselib=`basename $lib` if [ "$baseexe" = "$baselib" ] then echo changing id to $baselib for $exe install_name_tool -id $baselib $exe else echo changing path id for $lib in $exe install_name_tool -change $lib /Library/Oracle/instantclie +nt_11_2/$baselib $exe fi done done
      2. Go to /Library/Oracle/instant_client_11_2, and run the script
        [/Library/Oracle/instantclient_11_2] sudo bash ~/myScrips//fix_dyld.sh + Password: adjusting executable ./adrci adjusting lib /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1 changing path id for /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dyli +b.11.1 in ./adrci adjusting lib /ade/dosulliv_ldapmac/oracle/ldap/lib/libnnz11.dylib [... deleted stuff...]

  • Prepare makefile (again). You must run as administrator because the process will want to create a soft link in your /Library/Oracle/instant_client_11_2 directory.
    [~/Downloads/DBD-Oracle-1.75_2] sudo perl Makefile.PL Password: [... deleted stuff ...] Using DBI 1.634 (for perl 5.018002 on darwin-thread-multi-2level) inst +alled in /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBI/ Configuring DBD::Oracle for perl 5.018002 on darwin (darwin-thread-mul +ti-2level) [... deleted stuff...] Looks like an Instant Client installation, okay You don't have a libclntsh.dylib file, only /Library/Oracle/instantcli +ent_11_2/libclntsh.dylib.11.1 So I'm going to create a /Library/Oracle/instantclient_11_2/libclntsh. +dylib symlink to /Library/Oracle/instantclient_11_2/libclntsh.dylib.1 +1.1 [...deleted stuff...] Writing Makefile for DBD::Oracle Writing MYMETA.yml and MYMETA.json
  • make
    [~/Downloads/DBD-Oracle-1.75_2] make cp lib/DBD/Oracle/Object.pm blib/lib/DBD/Oracle/Object.pm cp lib/DBD/Oracle/GetInfo.pm blib/lib/DBD/Oracle/GetInfo.pm cp lib/DBD/Oracle/Troubleshooting/Aix.pod blib/lib/DBD/Oracle/Troubles +hooting/Aix.pod cp lib/DBD/Oracle/Troubleshooting/Sun.pod blib/lib/DBD/Oracle/Troubles +hooting/Sun.pod [... deleted stuff ...] Manifying blib/man3/DBD::Oracle::Troubleshooting.3pm Manifying blib/man3/DBD::Oracle::Troubleshooting::Win64.3pm Manifying blib/man3/DBD::Oracle::Troubleshooting::Vms.3pm Manifying blib/man3/DBD::Oracle::Troubleshooting::Linux.3pm Manifying blib/man3/DBD::Oracle::Troubleshooting::Macos.3pm Manifying blib/man3/DBD::Oracle::Object.3pm Manifying blib/man3/DBD::Oracle::Troubleshooting::Win32.3pm
  • test (this fails on el capitaine, probably doesn't on earlier version of Mac ??)
    [~/Downloads/DBD-Oracle-1.75_2] make test PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t t/000-report-versions-tiny.t .. # [... deleted stuff ... mostly version numbers of required modules ...] t/000-report-versions-tiny.t .. ok t/00versions.t ................ Can't load '/Users/sandy/Downloads/DBD-Oracle-1.75_2/blib/arch/auto/DB +D/Oracle/Oracle.bundle' for module DBD::Oracle: dlopen(/Users/sandy/Downloads/DBD-Oracle-1.75_ +2/blib/arch/auto/DBD/Oracle/Oracle.bundle, 2): Library not loaded: libclntsh.dylib.11.1 Referenced from: /Users/sandy/Downloads/DBD-Oracle-1.75_2/blib/arch/au +to/DBD/Oracle/Oracle.bundle Reason: unsafe use of relative rpath libclntsh.dylib.11.1 in /Users/sandy/Downloads/DBD-Oracle-1.75_2/blib/arch/auto/DBD/Oracle/Ora +cle.bundle with restricted binary at /System/Library/Perl/5.18/darwin-thread-mult +i-2level/DynaLoader.pm line 194. at t/00versions.t line 10. [... more errors ...]
  • fix "unsafe use of relative rpath"
    • Note that the path name of the Oracle.bundle would need to be changed to reflect your situation (check the error message for the exact location of the perl file it is complaining about)
    sudo install_name_tool -change libclntsh.dylib.11.1 /Library/Oracle/in +stantclient_11_2/libclntsh.dylib.11.1 /Users/sandy/Downloads/DBD-Oracle-1.75_2/blib/arch/auto/DBD/Oracle/Ora +cle.bundle
  • test again
    [~/Downloads/DBD-Oracle-1.75_2] make test PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib/lib', 'blib/arch')" t/*.t t/000-report-versions-tiny.t .. # [... deleted stuff ...] t/000-report-versions-tiny.t .. ok t/00versions.t ................ # OCI client library version: t/00versions.t ................ ok t/01base.t .................... ok t/10general.t ................. skipped: Unable to connect to Oracle t/12impdata.t ................. skipped: Unable to connect to Oracle [... deleted stuff ...] All tests successful. Files=38, Tests=9, 8 wallclock secs ( 0.11 usr 0.06 sys + 6.33 cusr + 0.96 csys = 7.46 CPU) Result: PASS
  • install
    sudo make install

    My final test

    [~/Downloads] cat test_connection.pl #!/usr/bin/perl use strict; use warnings; use DBD::Oracle; use DBI; my $user= "user"; my $passwd = "password"; my $dbh = DBI->connect("dbi:Oracle:ORCL", $user, $passwd); [~/Downloads] perl test_connection.pl [~/Downloads]


    1. http://blog.dbi-services.com/install-oracle-instant-client-perl-dbdoracle-mac-os-x-yosemite/

    2. http://www.toadworld.com/products/toad-mac-edition/b/weblog/archive/2013/07/02/setting-up-a-connection-to-oracle-on-your-mac

    3. http://stackoverflow.com/questions/33275605/el-capitan-perl-dbd-unsafe-use-of-relative-path

    4. http://blog.caseylucas.com/2013/03/03/oracle-sqlplus-and-instant-client-on-mac-osx-without-dyld_library_path/
  • Context, pedantry and appropriate response.
    6 direct replies — Read more / Contribute
    by BrowserUk
    on Jan 02, 2016 at 05:51

      Nit-picking pedantry is the bane of productive discourse.

      A not uncommon question in life is: "How much do you weigh"? To which we generally respond with something like: "nn pounds" or "nn kilos".

      Of course, if we last weighed ourselves naked having just stepped out of the shower, and we are currently wearing a full set of skiing gear; or if a holiday weekend or half a year has intervened, then our responses may be slightly or even wildly inaccurate. Which may or may not be okay depending on who is asking and why; but we generally know how much thought we should give to the accuracy and qualification of our responses from the context of the question.

      Of course, we don't really "weigh" what we weigh. We have a mass of a certain number of Newtons that only becomes a weight in the presence of a particular value of gravity.

      Ie. we 'weigh' differently on the surface of the Earth than we would on the Moon or in the ISS. And we would 'weigh' differently again if we were bridge of the Enterprise at Warp factor 10 and the inertial stabilizers failed.

      But no one ever responds to the target question with "nn Newtons"; or qualifies their "nn pounds/kilos" with "whilst naked, at a distance of nn miles/meters from the center of the Earth, whilst traveling at sub-relativistic speeds, and after a week or more of nominally average calorific intake and expenditure".

      And thank Dog they don't! Without we tailor and truncate our answers to the contexts in which the questions are asked, life would become quagmired in a treacle of inferable verbiage. And intolerable.

      Which is why mealy-mouthed, oneupmanship, pedantry posts like this deserve the response it got.

      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". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
    Stop Using Perl pt. 2
    5 direct replies — Read more / Contribute
    by sushi
    on Dec 29, 2015 at 00:01

      The Perl Jam 2: The Camel Strikes Back (32c3) https://www.youtube.com/watch?v=eH_u3C2WwQ0

      Link to discussion of last year's talk: 1111750

      I cringed the first talk, but it seems like this talk is more productive. Summary:

      • Hashes and arrays are considered "secure" (???)
      • SQL injections happen when you don't sanitize input (not exactly groundbreaking)
      • Results from various CGI-like modules are not standardized
      • Real bug in example CGI.pm code
      • <> does strange things when given something other than a file (strange to anyone who hasn't memorized the camel book)
      • open() creates a file descriptor unless it's used with | in which case it executes
      I sincerely hope there will not be a Stop Using Perl pt 3. I can only handle someone complaining about list flattening for so long.
    XML::Simple needs to go!
    7 direct replies — Read more / Contribute
    by Preceptor
    on Dec 21, 2015 at 05:18

      If there's one module that I think really needs to get thrown out of CPAN, it's this one. Why? Well, generally I'm forgiving - don't like a module; don't use it. Problem is - XML::Simple is false advertising - it commonly gets installed because it's "Simple", and that's simply not the case at all.

      I see a steady stream of questions - both here and on Stack Overflow - about this module, because someone's been tripped up again by how this module tries to coerce a more complex data structure into a less complicated one.

      That's really the root of the problem - just like parsing HTML with regex - the approach is fundamentally flawed.

      You can use regex to grab a value out of HTML/XML. It's nasty and brittle, but sometimes a dirty hack is expedient.

      And the same is true, I contend, of XML::Simple - it's the 'parsing with a regex' sort of solution. In that it can sort of work, in some scenarios but pretty fundamentally it's a bad solution to the problem at hand.

      But were the module called anything else this wouldn't be a problem. There's a lot of stuff in the CPAN namespace that I've never used or installed - that's fine, that's kind of the point.

      But many an unwary newbie has been caught out by it - there are a number of "Simple" modules that offer cut down interfaces for a limited subset of operations. LWP::Simple is a good example - it offers a cut down interface to the basic tasks one might need to accomplish with LWP.

      This module is official discouraged in it's module doc page but it's still picked up as the "Simple" answer.

      Is there precedent for renaming a module in CPAN? I know it's not really an option to just delete it, because there's probably some legacy code depending on it (as much as I think they should be rewriting it, that isn't really my call to make!). But it really does suffer from all the things that have given perl a bit of a bad name in the past - it's a sure road to some rather hacky/nasty code.

    Yak Shaving for Fun and Profit (or How I Learned to Stop Worry and Love Perl 6)
    1 direct reply — Read more / Contribute
    by raiph
    on Dec 16, 2015 at 13:02

      This post is about Perl 6, not rock solid Perl 5

      Today's Perl 6 advent calendar looks like it may be of more than average interest to monks interested in the sort of thing -Ofun meant in 2015 when trying to write a non-trivial Perl 6 application: Yak Shaving for Fun and Profit (or How I Learned to Stop Worry and Love Perl 6)

      Trolls are expected to join our meditation. Herewith a collective "happy winter solstice" hug for them all from me and on behalf of a bug-eyed butterfly. I ask that those of us that prefer to don the robes of a monk rather than dress up as trolls do their very best to leave the trolls alone or just surround them with genuine unconditional love. Imagine how cool it would be if there were no attacks in this thread, or, more realistically, there were no responses to attacks no matter how personal or pernicious. Thanks for your cooperation. :)

      And finally, here's another happy (near) winter solstice greeting, this time for the whole monastery. I learn a lot about being humble and encouraging my compassionate self in posts here and I appreciate this gift that keeps giving.

    What the HEY is up with the cartoon butterfly for "Perl 6" ?!
    14 direct replies — Read more / Contribute
    by 1nickt
    on Dec 07, 2015 at 08:10

      Yes, this is a rant. I'm trying to rant less. But this is something I feel have to say, in the admittedly faint hope that it will reach the ears of someone in charge.

      Today I went to look at "Perl 6." The Perl Weekly newsletter has been turning more and more into a promotional rag for "Perl 6," and then I saw that a good deal of the London Perl Workshop has been dedicated to it. So, after 20 years more or less of programming perl, I figured I should at least swing by and see what all the distraction is about.

      Lo and behold when I get to the website of the "plucky little sister of Perl 5" (who wrote this marketing pablum, a 20-yr old Communications major?), I am greeted by a multicolored butterfly that looks like it belongs on the Disney Channel early-afternoon lineup.

      What the HEY?!

      Are you out of your MIND?

      In the interests of keeping this rant short, I'll just say that if you were trying to convince serious programmers that "Perl 6" was worth any of their time to investigate, you could not have chosen a less effective design. To me this kindergarden art symbolizes:

      • shallowness
      • infantilism
      • dumbing down to try to widen the appeal
      • the ascendency of communications-major type people over critical thinkers and engineers
      • Microsoft Windows (remember the paper clip?)
      • the complete lack of seriousness of "Perl 6" as a programming language
      and so on.

      I write Perl for a living, for companies that use it to do business and make money. It's serious stuff, and it's fun because of how challenging it is, not because of a pink and purple anthropomorphic icon.

      To the "Perl 6" people: I was already very skeptical of your project, given its debaculous history. Well, now I am convinced. You could not have done more to prove to me that, as I suspected, it is a vanity project of a handful of the brightest, most bored Perl 5 gurus, that has no application in the real world in which I live and program.

      To be clear, your butterfly has turned me off from even beginning to read the content of your site, and I would imagine that I am very far from being the only one.

      (Note: I looked for a place on the "Perl 6" website to post this as feedback, but no such link was to be found.)

      Larry Wall would be rolling in his grave. Oh, wait ...

      But for the rest of you, if you were that bored, couldn't you have just gone off quietly and tackled some new field of human endeavour if you were "over" Perl, like, for example, how tchrist became the arbiter of all aspects of the English language on Stackexchange? Why the need to try to "rebrand" Perl as a consumer product for millenial schoolgirls?

      Can't Perl users file a class-action suit or something to force the Butterfly People to pick another name for their hobby?

      The way forward always starts with a minimal test.

    Add your Meditation
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.