Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
The stupid question is the question not asked
 
PerlMonks

The Monastery Gates

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

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

Want Mega XP? Prepare to have your hopes dashed, join in on the: poll ideas quest 2012  (Don't worry; you've got plenty of time.)

New Questions
Prototype problem for XS module
4 direct replies — Read more / Contribute
by chessgui
on Feb 05, 2012 at 11:02
    I've managed to put together an XS module which is an interface to the Windows MessageBox function (my ultimate goal is to speak to the System Tray). The XS code:
    #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "windows.h" MODULE = Mytest PACKAGE = Mytest int hello(input) unsigned int input CODE: int x=MessageBox(NULL,TEXT("Text"),TEXT("Caption"),input); RETVAL=x; OUTPUT: RETVAL
    This code works. However if I want to use the 'UINT' data type (which is in the original declaration of the function) instead of 'unsigned int' the make fails:
    Error: 'UINT' not in typemap in Mytest.xs, line 12 Please specify prototyping behavior for Mytest.xs (see perlxs manual)
    The perlxs manual says that prototypes can be enabled and disabled but I find no guidance for how to use a predefined C prototype.
How to get Pod::Coverage to stop calling my export naked
4 direct replies — Read more / Contribute
by Oberon
on Feb 04, 2012 at 14:33

    O wise and benevolent masters, I humbly lay my unworthy question at your feet:

    My module exports a compile-time constant to its caller. It's important that it be a compile-time constant so the optimizer can take advantage of that. So I create it thusly (in my import):

    eval "sub ${caller_package}::DEBUG () { $debug_value }";

    The problem is that now Pod::Coverage calls DEBUG a naked subroutine in the caller, which of course fails the ubiquitous Test::Pod::Coverage tests. I decided to look and see how Pod::Coverage was figuring out whether a sub was imported or not, and discovered this bit of Black Magic:

    # see if said method wasn't just imported from elsewhere my $glob = do { no strict 'refs'; \*{$sym} }; my $o = B::svref_2object($glob); # in 5.005 this flag is not exposed via B, though it exists my $imported_cv = eval { B::GVf_IMPORTED_CV() } || 0x80; next if $o->GvFLAGS & $imported_cv;

    After my head stopped hurting, I decided to just give up and change my code so it really is imported, like so:

    eval "sub DEBUG () { $debug_value }"; *{ join('::', $caller_package, 'DEBUG') } = \&DEBUG;

    Sure enough, that shuts up Pod::Coverage, but now my compile-time constant isn't a compile-time constant any more. :-/

    Now, obviously I know that I can just tell Test::Pod::Coverage to ignore that routine, but I don't think it's reasonable to tell anyone who uses my module to do so. I'm willing to set that bitflag that Pod::Coverage is relying on manually, but I have no idea how to go about that ... that's perlguts stuff, which is a bit beyond my skill level (although I'm willing to attempt it, if anyone could point me in the right direction).

    Any thoughts on the best way to get Pod::Coverage to ignore my routine when it's exported to other packages?

win32::ole and MS Office 2010 over cgi
2 direct replies — Read more / Contribute
by wal77
on Feb 04, 2012 at 10:57

    We have a web application runnung on Windows Server 2003, Apache and MS Office 2003. Win32::Ole generates word documents initiated over a CGI form. All works pretty. Now I have to install a new server based on Windows Server 2008 R2 Standard with Office 2010.

    Apache runs as priveleged user, but the script hangs on $word = Win32::OLE->new('Word.Application', sub {$_[0]->Quit;} till browser timeout message coming, no errors in perl($Win32::OLE::Warn = 3;), Apache or Windows. Seems to be Word waiting for a confirmation, but I can't see it ({visible} = 1).

    use Win32::OLE; $Win32::OLE::Warn = 3; eval {$word = Win32::OLE->GetActiveObject('Word.Application')}; die "Word not installed" if $@; unless (defined $word) { $word = Win32::OLE->new('Word.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Word"; } $word->Activate; $word->{visible} = 1; my $doc = $word->Documents->Open("$oldfile"); ....... $word->ActiveDocument->SaveAs($newfile); $doc->Close(); $word -> Quit;

    Can you halp me? Regards, wal77

find the continuity in the data file
5 direct replies — Read more / Contribute
by extrem
on Feb 04, 2012 at 10:28
    i have a data file which has numbers which are continous at certain time and not continous ie =

    16 107 108 110 112 114 115 117 118 119 120 121 122 123 124 125 127 128 130 132 133 135 136 138 142 146 149 150 154 156 157 158 159 161 162

    but there would be certain level where the numbers would be continous for more than 2500 numbers. i want to find such data and print out. please anyone tell me how.
What does "increment $| or set it to 1" mean for my CGI app?
2 direct replies — Read more / Contribute
by isync
on Feb 04, 2012 at 08:36
    I am using CGI::Application::Plugin::Stream in one of the runmodes of a cgi app. And it sometimes behaves strange, especially under FCGI.

    Now I came across this note in the ::Stream docs: "It's recommended that you increment $| (or set it to 1), which will autoflush the buffer as your application is streaming out the file."
    The special vars docs say "$| means If set to nonzero, forces a flush after every write or print", but how do I use this in my cgi app?
    • Why doesn't ::Stream set it after it has finished printing stuff to STDOUT automagically?
    • Shall I do
      $| = 1; $self->stream_file( $file ) $| = 0; return;
      in my runmode?
    • Or does it mean I should switch the buffer mode in general for the whole app by stating $| = 1; in the setup() stage of CGI::App??
Incremental XML parsing
2 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 04, 2012 at 08:22
    I need to parse many large XML documents, so I want to use an incremental parser to conserve memory. The only incremental parser I could find was XML::SAX::Expat::Incremental, but it's too slow. Is it possible to use XML::LibXML::Reader to do this? Or is there a better alternative?
execute a file, then send terminate command?
2 direct replies — Read more / Contribute
by perlpreben
on Feb 04, 2012 at 08:13

    Hi,

    Unwillingly i have to use windows for a project of mine. And I need to execute an .exe file.

    What I have done is to wrap this into a simple perl script, giving me somewhat control, like;

    open SYS,"windows_exe_file.exe|"; while(<SYS>){ #parse magic here.. }

    The downside is that I cant seem to get STDOUT before the program has ran for quite a while, then it spewes out some chuncks of STDOUT. Windows problem propably. But my backup solution is to use the .exe files EXPORT function (built in reporting function, not related to perl). However, I would need to "PRESS" the the button "ESC" to the program, for it to quit and write the log files.

    Is this even possible?

CGI error: "Invalid header value contains a newline not followed by whitespace"
2 direct replies — Read more / Contribute
by MyMonkName
on Feb 03, 2012 at 22:19
    Hi Monks,

    I have a cgi script that is supposed to redirect the user on success. I was running it on a somewhat antiquated version of Ubuntu, and when I upgraded it to Lucid (running Perl 5.10.1 under apache 2.2.14), it stopped working. The error message is,

    Invalid header value contains a newline not followed by whitespace: status: 302 found location: http://localhost/

    The relevant code seems to be this:

    my $set_username = $q->cookie( -name => "user_name", -value => $user_name, -expires => "+1d", ); my $set_session = $q->cookie( -name => "session", -value => $secret, -expires => "+1d", ); print $q->header( -cookie => [ $set_session, $set_username ], $q->redirect("http://localhost/"));

    I've tried chomping the relevant variables, adding whitespace, etc., but it doesn't seem to help. As you may have guessed, it is a login script. Does anybody have any pointers on how to fix this?

    Thanks!
scalar vs list context
5 direct replies — Read more / Contribute
by kevind0718
on Feb 03, 2012 at 20:19
    Hello All:

    Working my way through Learning Perl (the llama book), specifically the section Scalar and List Context.

    Please consider the following:

    my $x; my @array; @array = qw( a b c); ($x) = qw( a b c); print $x . "\n"; $x = qw( a b c); print $x . "\n";
    Which produces:

    C:\dev\learningPerl>perl ex3c.pl a c
    In this assignment: ($x) = qw( a b c);

    In my mind we have list to list. The list on the left only has one slot so the other two values are lost.

    Can some please explain what is going on here:

    $x = qw( a b c);

    and why does "c" get assigned to $x

    Many thanks for your kind assistance.

    Best

    KD
Nested (sql) transactions
4 direct replies — Read more / Contribute
by clueless newbie
on Feb 03, 2012 at 17:26

    Nested transactions - thoughts, suggestions and comments requested.

    Microsoft's SQL-Server supports nested transactions something that seem "natural" to Perl's notion of modules. Yet many databases do not support nested transactions - MySQL comes to mind. Perhaps the very nature of my being somewhat of a "clueless newbie" incited me to wonder if it's feasible to implement what amounts to nested transactions for those databases that don't support it.

    I've been experimenting with "code" that looks like

    ### Transaction starts my $dbh=DBI->connect(...); transactionalize { # Code to be run as a transaction here #- no begin_work, commit, rollback, START TRAN, COMMIT TRAN, ROL +LBACK TRAN ... } using ($dbh); ### Transaction ends

    and implemented transactionalize/using (along the lines of Try::Tiny's try/catch) with

    { # This code implement the transactionalize { ... } using ( dbh ); my (@dbh_AO,$dbh_HRef,$error_E); sub transactionalize(&;$) { my ($body_CRef,$dbh_CRef)=@_; eval { ### Setting dbh_O ... push(@dbh_AO,(defined $dbh_CRef) ? $dbh_CRef->() : $Defa +ultdbh_O); local $dbh_AO[-1]->{RaiseError}=1; warn "@dbh_AO "; ### BEGIN TRANSACTION ... unless (exists $dbh_HRef->{$dbh_AO[-1]}) { $dbh_AO[-1]->begin_work; $dbh_HRef->{$dbh_AO[-1]}=$dbh_AO[-1]; }; ### Do the stuff here ... $body_CRef->(); ### COMMIT TRANSACTION ... if (@dbh_AO == 1) { for my $dbh_s (keys %$dbh_HRef) { ### $dbh_s $dbh_HRef->{$dbh_s}->commit(); }; }; pop(@dbh_AO); }; if ($@) { $error_E||=$@; ### ROLLBACK TRANSACTION ... if (@dbh_AO == 1) { for my $dbh_s (keys %$dbh_HRef) { ### $dbh_s eval { $dbh_HRef->{$dbh_s}->rollback(); }; }; }; pop(@dbh_AO); Carp::confess $error_E; }; } # transactionalize {}: sub using($) { my $dbh_O=shift; ### <where>: $dbh_O return sub { return $dbh_O; }; }; };

    Initial trials give me hope. Much more testing remains.

    There are no doubt bugs that remain and enhancements that are needed.

    Thoughts, suggestions, comments appreciated.

    added: RaiseError

Solaris problem or compile options
4 direct replies — Read more / Contribute
by ckevinj
on Feb 03, 2012 at 15:51

    I've been trying to compile Crypt::OpenSSL::X509 on my Solaris boxes and I am losing my hair too fast over it. It compiled fine under Mac OSX.

    So I'm down to wondering if it something with the way the Perl binaries were compiled.

    Here's the rundown, I'm hoping someone has some wisdom for me.

    Initial problems right away with the execution of 'perl Makefile.PL', complaining about about an option (-lcrypt). I wonder if this isn't a linux thing so I comment that out of the Makefile.PL and adjust the inc and lib paths in the PL to point to a known, good, 64bit OpenSSL library and the include file for the opencsw location:

    use inc::Module::Install; name('Crypt-OpenSSL-X509'); license('perl'); perl_version('5.005'); all_from('X509.pm'); homepage 'https://github.com/dsully/perl-crypt-openssl-x509'; bugtracker 'https://github.com/dsully/perl-crypt-openssl-x509/issues'; requires_external_cc(); cc_inc_paths('/opt/csw/include'); cc_lib_paths('/opt/csw/lib/sparcv9'); #cc_lib_links('crypto'); cc_optimize_flags('-O2 -g -Wall -Werror -mcpu=v9 -m64 '); auto_install(); WriteAll();
    I have a 64 bit perl compiled.
    ckevinj@wbz-r01:Crypt-OpenSSL-X509-1.800.2 $file `which perl` /tools/perl/5_14_2/bin/perl: ELF 64-bit MSB executable SPARCV9 Vers +ion 1, dynamically linked, not stripped
    The Makefile is made cleanly.
    ckevinj@wbz-r01:Crypt-OpenSSL-X509-1.800.2 $perl Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for Crypt::OpenSSL::X509 Writing MYMETA.yml and MYMETA.json
    The gmake is clean.
    ckevinj@wbz-r01:Crypt-OpenSSL-X509-1.800.2 $gmake -i cp X509.pm blib/lib/Crypt/OpenSSL/X509.pm /tools/perl/5_14_2/bin/perl "-Iinc" /tools/perl/5_14_2/lib/5.14.2/ExtU +tils/xsubpp -typemap /tools/perl/5_14_2/lib/5.14.2/ExtUtils/typemap +-typemap typemap X509.xs > X509.xsc && mv X509.xsc X509.c gcc -c -I/opt/csw/include -mcpu=v9 -m64 -fno-strict-aliasing -pipe -f +stack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DPERL_USE +_SAFE_PUTENV -DPERL_USE_SAFE_PUTENV -O2 -g -Wall -Werror -mcpu=v9 -m6 +4 -DVERSION=\"1.800.2\" -DXS_VERSION=\"1.800.2\" -fPIC "-I/tools/p +erl/5_14_2/lib/5.14.2/sun4-solaris-64/CORE" X509.c Running Mkbootstrap for Crypt::OpenSSL::X509 () chmod 644 X509.bs rm -f blib/arch/auto/Crypt/OpenSSL/X509/X509.so gcc -mcpu=v9 -m64 -G -L/usr/lib/sparcv9 -fstack-protector -G X509.o +-o blib/arch/auto/Crypt/OpenSSL/X509/X509.so \ \ chmod 755 blib/arch/auto/Crypt/OpenSSL/X509/X509.so cp X509.bs blib/arch/auto/Crypt/OpenSSL/X509/X509.bs chmod 644 blib/arch/auto/Crypt/OpenSSL/X509/X509.bs Manifying blib/man3/Crypt::OpenSSL::X509.3
    But the object is not useable. It has so many missing symbols that seem to be mostly Perl related.
    ckevinj@wbz-r01:Crypt-OpenSSL-X509-1.800.2 $ldd -d blib/arch/auto/Cryp +t/OpenSSL/X509/X509.so libssp.so.0 => /opt/csw/lib/sparcv9/libssp.so.0 libc.so.1 => /lib/64/libc.so.1 libgcc_s.so.1 => /opt/csw/lib/sparcv9/libgcc_s.so.1 symbol not found: main (blib/arch/auto/Crypt/OpenSSL/ +X509/X509.so) symbol not found: PL_sv_undef (blib/arch/auto/Crypt/ +OpenSSL/X509/X509.so) symbol not found: PL_markstack_ptr (blib/arch/aut +o/Crypt/OpenSSL/X509/X509.so) symbol not found: PL_stack_sp (blib/arch/auto/Crypt/ +OpenSSL/X509/X509.so) symbol not found: PL_stack_base (blib/arch/auto/Crypt/ +OpenSSL/X509/X509.so) symbol not found: PL_op (blib/arch/auto/Crypt/OpenSSL/ +X509/X509.so) symbol not found: PL_curpad (blib/arch/auto/Crypt/ +OpenSSL/X509/X509.so) symbol not found: PL_sv_no (blib/arch/auto/Crypt/ +OpenSSL/X509/X509.so) symbol not found: PL_sv_yes (blib/arch/auto/Crypt/ +OpenSSL/X509/X509.so) symbol not found: i2d_ASN1_HEADER (blib/arch/aut +o/Crypt/OpenSSL/X509/X509.so) symbol not found: PL_unitcheckav (blib/arch/aut +o/Crypt/OpenSSL/X509/X509.so) symbol not found: PL_scopestack_ix (blib/arch/aut +o/Crypt/OpenSSL/X509/X509.so) libm.so.2 => /lib/64/libm.so.2 /platform/SUNW,Sun-Fire-T1000/lib/sparcv9/libc_psr.so.1
    My Perl binary is not multi-threaded. I looked for libperl.so in the /tools/perl/5_14_2 path to put in my LD_LIBRARY_PATH_64, but there was only a libperl.a.

    I did find some issues with a tool where some one was getting similar symbol issues when they were trying to run a module that expected a multi-threaded perl but it wasn't. So I'm attempting to recompile Perl again as multi-threaded to test that possibility.

Net::LDAP help with distinguished name
1 direct reply — Read more / Contribute
by Discreet Entity
on Feb 03, 2012 at 12:50
    Folks:

    I have used the Net::LDAP module lots of timees to do searches. However, I cannot seem to figure out how to get the attributes for a specific user when I already have the distinguished name.

    For instance, I have a string like so:

    "CN=JUSER,OU=ACCT,OU=USERS,DC=MYCOMPANY,DC=COM"

    I just need to connect to that specific user object and get the properties. I have read all the help on Net::LDAP and searched but every example seems to be about doing a search and I don't need to search since I already have the dn.

    I can do this easily in vbscript by just setting the object to the dn. Surely I can do something similar in perl.

    Please help explain what I'm missing.

    Thanks,

New Meditations
P2P Architectures, SOPA/PIPA and freedom from censorship
4 direct replies — Read more / Contribute
by Steve_BZ
on Jan 31, 2012 at 15:07

    Hi Fellow Monks,

    What with all the stuff going down about SOPA and PIPA, I've sort of being keeping my head down and hoping it would go away. But then I lost my YouTube password, and it automatically logged me on with Google. I was a little shocked. I did some research and I found what I should have known anyway, and you probably already know, that Google owns pretty much the whole Universe, apart from Microsoft, which now has only 3% of the search engine market plus the 5% it gets from Yahoo (also powered by Bing), and Facebook (I think).

    So I started to wonder are there ways round it and I came across yacy.net, a P2P search engine, sadly for us written in Java. Although it's been around for a few years, it's still in it's infancy as far as performance and user experience, but it got me thinking.

    It seems to me that what is a dynamic network of global peer-peer contributors (like us) is much harder to influence than a single huge company with all the political ties that it inevitably has.

    So I am asking my fellow monks, what experience does Perl and the Perl community have on P2P applications and what is there out there that we can draw on in our own development.

    As usual I look forward to your thoughts.

    Regards

    Steve

New Cool Uses for Perl
xkcd-style password generation
4 direct replies — Read more / Contribute
by Tanktalus
on Feb 01, 2012 at 15:27

    To create a password a la xkcd:

    perl -le '@w=<>;chomp@w;print join" ",map{$w[rand@w]}1..4'</usr/share/ +dict/words
    But then I get bizarre combinations like "revolutionizer ananda Pleurobrachiidae squaller" - I don't care what xkcd says, I'm not remembering that one. :)

    Update: Slightly better, though a bit nasty to whoever owns the domain...

    perl -MLWP::Simple -lE '@w=get("http://jbauman.com/gsl.html")=~/^\d+\s ++\d+\s+([a-z]+)/xmsg;say join" ",map{$w[rand@w]}1..4'
    which gets me, as an example, "rather weight decay punctual". Much easier to memorise. I think I might keep this one :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (17)
As of 2012-02-06 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When I see "10", I think:











    Results (195 votes), past polls