Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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.

New Questions
Default named params with an embedded hash
1 direct reply — Read more / Contribute
by neilwatson
on Aug 28, 2014 at 15:12

    Greetings,

    I'm trying to use named parameters with default values. For a normal hash this is simple, but I have a more complex data structure.
    #!/usr/bin/perl use strict; use warnings; use feature 'say'; use Data::Dumper; my %valid_inputs = ( one => 1, two => 2 ); validate( valid_inputs => \%valid_inputs, max_record_length => 72, ); sub validate { my %params = ( valid_inputs => { one => 'one', two => 'two', three => 'three', four => 'four', }, max_record_length => 24, @_, ); my $valid_inputs = $params{valid_inputs}; say '@_ ['.Dumper( \@_ ).']'; say '%params ['.Dumper( \%params ).']'; say '%valid_inputs ['.Dumper( \%valid_inputs ).']'; } #EOF Output: @_ [$VAR1 = [ 'valid_inputs', { 'two' => 2, 'one' => 1 }, 'max_record_length', 72 ]; ] %params [$VAR1 = { 'valid_inputs' => { 'two' => 2, 'one' => 1 }, 'max_record_length' => 72 }; ] %valid_inputs [$VAR1 = { 'two' => 2, 'one' => 1 }; ]

    Because valid_inputs is a reference it over writes the defaults completely rather than just the same keys as with max_record_length. If make valid_inputs not a refence the final complete hash is scrambled and flat. Is there an elegant solution?

    Neil Watson
    watson-wilson.ca

How to encode after using HTML::Strip
1 direct reply — Read more / Contribute
by myfrndjk
on Aug 28, 2014 at 14:36

    Hi I am trying to encode the html page using cp1252 since it has lot of special characters like € and £ pounds but when i try to save those contents after using HTML::strip .All were displayed as junk values.I tried to encode using cp1252 but its not working.Please help me to fix the issue.

    use strict; use warnings; use HTML::TreeBuilder::XPath; use LWP::UserAgent ; use HTTP::Request ; use HTML::Entities; use HTML::Strip; use encoding "cp1252"; open (OUT, '>:encoding(cp1252)',"/home/local/ANT/jeyakuma/Desktop/test +.html"); my $URL = 'http://www.footlocker.eu/it/it/k/Customer-Service/Shipping. +aspx'; my $agent = LWP::UserAgent->new(agent => "Mozilla/5.0"); my $request = HTTP::Request->new(GET=> $URL); my $response = $agent->request($request); # Check the outcome of the response if ($response->is_success) { my $xp = HTML::TreeBuilder::XPath->new_from_content($response->decoded +_content); my $raw_html = $xp->findnodes_as_string('//div[@class="faq_text"]/p/st +rong/u[contains(.,\'spedizione Standard \')]'); my $hs = HTML::Strip->new(); my $clean_text = $hs->parse( $raw_html ); $hs->eof; print OUT $clean_text; } elsif ($response->is_error) { print "Error:$URL\n"; print $response->error_as_HTML; }

    Expected output :£ 60/

    current output : £ 60/â‚

Cursor keys with Tk::Hlist goes wrong
1 direct reply — Read more / Contribute
by luke67m
on Aug 28, 2014 at 12:45
    Hi monks. I'm trying to use Tk::Hlist in a panel for file selection. I'm trying to make the panel usable both under linux and windows. I'm a newby. The hlist has 3 Columns. Here the problem : Under linux, if I define the first column with itemCreate, the cursor keys up and down works in unpredictable ways : Up sometimes goes down and down sometimes goes up. Under windows everything seems to work. Here a sample of my code
    ########################################################### #this not work my $e = $tree->add( $dir ); $tree->itemCreate ($e, 0, -itemtype => 'imagetext', -text => $text, -image => $tree->Getimage("folder"), -style=> $Col0StyleA ); #this not work ########################################################### #this work # my $e = $tree->add( $dir , -text => $text, -image => $tree->Geti +mage("folder"), # ); #this work ###########################################################
    I'm using winxp strawberry 5.18 and lubuntu 14.4 . Feel free to ask for full source, I can publish it on sourceforge
Get variables from txt file
3 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 28, 2014 at 12:15

    Hi,

    I have written a perl script but I don't know how to get the variables from a txt file. Actually, I can read the txt file in hash and get the variables but I have a small issue. In the txt file I have some paths that include variables.

    The txt file with the variables looks like:

    V1=/home/user V2=$V1/test V3=$V2/file.txt

    I read the lines using:

    Read variables open my $vars, '<:utf8', "$Bin/vars.txt" or die $! ; while (<$vars>) { chomp; my ($key, $value) = split(/=/, $_); $vars{$key} = $value; } my $V1 = $vars{'V1'}; my $V2 = $vars{'V2'}; my $V3 = $vars{'V3'}; print "$V1\n"; print "$V2\n"; print "$V3\n"; close ($vars);

    The result that I get is:

    /home/user /$V1/test /$V2/file.txt

    but I want

    /home/user /home/user/test /home/user/test/file.txt

    I would appreciate any help.

Tcl module install issues
No replies — Read more | Post response
by CarolinaPerler
on Aug 28, 2014 at 10:19

    Trying to install the Tcl/Tk modules to do a GUI on AIX5.3. I have successfully built the Tcl libraries from source. And, I've been able to install the RPM packages via the AIX linux tools. However, I cannot get things combed straight.

    perl ./MakeFile.pl - works.
    make appears to work.
    make test fails spectacularly. Since Tcl.pm won't load, all tests fail.

    My suspicion is that there is a 32 vs 64 bit tangle. When I built the Tcl libraries from source I used --enable-64bit. As the build ran, I noticed a warning stating 64bit was not supported on AIX, and it reverted back to 32. The libs built and I can crankup tclsh. But, I'm suspicious that the 64bit Perl install is choking on the 32bit libraries.

    Any feedback about this specific issue would be appreciated. Also, any ideas on the wider process of getting Tcl/Tk and associated Perl modules installed on AIX5.3 would be appreciated.

    root@host:/opt/perl-5.14.4/downloads/modules/Tkx/Tcl-1.02# perl514 Mak +efile.PL LIBS = -Ltcl-core/aix -ltclstub8.4 INC = -Itcl-core/include DEFINE = -DUSE_TCL_STUBS Checking if your kit is complete... Looks good Warning: -Ltcl-core/aix changed to -L/opt/perl-5.14.4/downloads/module +s/Tkx/Tcl-1.02/tcl-core/aix Generating a Unix-style Makefile Writing Makefile for Tcl Writing MYMETA.yml and MYMETA.json root@host:/opt/perl-5.14.4/downloads/modules/Tkx/Tcl-1.02# make cp Tcl.pm blib/lib/Tcl.pm /usr/bin/perl514 -e 'use ExtUtils::Mksymlists; Mksymlists("NA +ME" => "Tcl", "DL_FUNCS" => { }, "FUNCLIST" => [], "DL_VARS" => []); +' Running Mkbootstrap for Tcl () chmod 644 Tcl.bs /usr/bin/perl514 /opt/perl-5.14.4/lib/5.14.4/ExtUtils/xsubpp +-typemap /opt/perl-5.14.4/lib/5.14.4/ExtUtils/typemap -typemap typema +p Tcl.xs > Tcl.xsc && mv Tcl.xsc Tcl.c Please specify prototyping behavior for Tcl.xs (see perlxs manual) gcc -maix64 -maix64 -c -Itcl-core/include -D_THREAD_SAFE -D_ +ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -DUSE_NATIVE_DLOPEN -DNEE +D_PTHREAD_INIT -fno-strict-aliasing -pipe -I/usr/local/include -maix6 +4 -DUSE_64_BIT_ALL -O -DVERSION=\"1.02\" -DXS_VERSION=\"1.02\" " +-I/opt/perl-5.14.4/lib/5.14.4/aix-thread-multi-64all/CORE" -DUSE_TCL +_STUBS Tcl.c rm -f blib/arch/auto/Tcl/Tcl.so gcc -maix64 -maix64 -Wl,-b64 -Wl,-bhalt:4 -Wl,-G -Wl,-bI:/opt +/perl-5.14.4/lib/5.14.4/aix-thread-multi-64all/CORE/perl.exp -Wl,-bE: +Tcl.exp -Wl,-bnoentry -lpthreads -lc -lm -L/usr/local/lib Tcl.o -o b +lib/arch/auto/Tcl/Tcl.so -L/opt/perl-5.14.4/downloads/module +s/Tkx/Tcl-1.02/tcl-core/aix -ltclstub8.4 chmod 755 blib/arch/auto/Tcl/Tcl.so /usr/bin/perl514 -MExtUtils::Command::MM -e 'cp_nonempty' -- +Tcl.bs blib/arch/auto/Tcl/Tcl.bs 644 Manifying blib/man3/Tcl.3 root@host:/opt/perl-5.14.4/downloads/modules/Tkx/Tcl-1.02# make test Running Mkbootstrap for Tcl () chmod 644 Tcl.bs PERL_DL_NONLAZY=1 /usr/bin/perl514 "-MExtUtils::Command::MM" " +-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0 +, 'blib/lib', 'blib/arch')" t/*.t t/call.t ........... Can't load '/opt/perl-5.14.4/downloads/modules/Tk +x/Tcl-1.02/blib/arch/auto/Tcl/Tcl.so' for module Tcl: rtld: 0712-001 +Symbol Tcl_InitStubs was referenced from module /opt/perl-5.14.4/downloads/modules/Tkx/Tcl-1.02/blib +/arch/auto/Tcl/Tcl.so(), but a runtime definition of the symbol was not found. rtld: 0712-001 Symbol tclStubsPtr was referenced from module /opt/perl-5.14.4/downloads/modules/Tkx/Tcl-1.02/blib +/arch/auto/Tcl/Tcl.so(), but a runtime definition of the symbol was not found. rtld: 0712-002 fatal error: exiting. at /opt/perl-5.14.4/lib/5.14.4/ai +x-thread-multi-64all/DynaLoader.pm line 190. at t/call.t line 6 Compilation failed in require at t/call.t line 6. BEGIN failed--compilation aborted at t/call.t line 6. Undefined subroutine &Tcl::_Finalize called at /opt/perl-5.14.4/downlo +ads/modules/Tkx/Tcl-1.02/blib/lib/Tcl.pm line 422. END failed--call queue aborted at t/call.t line 6. t/call.t ........... Dubious, test returned 22 (wstat 5632, 0x1600)
Sending module output to STDOUT in test
5 direct replies — Read more / Contribute
by loris
on Aug 28, 2014 at 08:21

    Dear Monks,

    I have a test using Test::More which is failing. I would like to debug the relevant subroutine in my module by inserting a print to see what is going on.

    How do can I see the output when I run the test with, say, prove?

    Thanks,

    loris

Error while reading .xls file
1 direct reply — Read more / Contribute
by a.alandkar
on Aug 28, 2014 at 06:53

    Hello all, I am using strawberry perl. Facing some issues.

    #! usr/bin/perl -w #use,strict; use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; my $workbook; my @labels = ('Parameter_Name','Parameter_Index','Storage_Class','Data +_Type','min_range_value','max_range_value','default_value','test_valu +e','mode_for_write','access_rights','view1','view2','view3','view4'); $workbook = Spreadsheet::WriteExcel->new('perl.xls'); $worksheet = $workbook->add_worksheet(); for($for=0;$for<13;$for++) { $worksheet->write(0,$for,$labels[$for]); # print($for); # print($labels[$for]); } &get_max_row_col(); sub get_max_row_col() { my $parser = Spreadsheet::ParseExcel->new(); my $workbook1 = $parser->parse('perl.xls'); for my $worksheet ( $workbook1->worksheet(0) ) { my ( $row_min, $row_max ) = $worksheet->row_range(); # + Find out the worksheet ranges my ( $col_min, $col_max ) = $worksheet->col_range(); print ("max_rows = $row_max \n"); print ("max_cols = $col_max \n"); } }

    when i compile this code it gives me an error saying (C:\Users\Ambar.Alandkar\Desktop\Ambar\Perl-Test>perl XL_Handling.pl Can't call method "worksheet" on an undefined value at XL_Handling.pl line 29.) but when i run the get_max_row_col() subroutine code making a separate file it works well without any error. Is there anything missing or wrong in implementation.? Please help.

mqseries_1.34 Makefile loop
No replies — Read more | Post response
by itc
on Aug 28, 2014 at 06:40

    I am looking for help with a problem installing the MQseries-1.34 Perl API.

    I had successfully installed it in our sandpit server, then moved onto our development server and had an issue with the Makefile resulting in a looping zombie process requiring the server to be rebooted.

    I then had the sandpit server rebuilt to mirror development and have reproduced the issue on the sandpit server.

    After installing required pre-requisites, here is what I see for the Makefile….

    $ sudo perl Makefile.PL verbose Password: Checking if your kit is complete... Looks good ABSTRACT => q[Interface to IBM's MQSeries Product] AUTHOR => q[MQ Engineering Group <mqseries@cpan.org>] NAME => q[MQSeries] PREREQ_PM => { Params::Validate=>q[1.00], Test::Simple=>q[0.62], Con +vert::EBCDIC=>q[0.06], Test::Pod=>q[1.20] } VERSION_FROM => q[MQSeries.pm] Using PERL=/usr/bin/perl

    ….it does not respond beyond this point and continues looping indefinitely. Additional info below

    AIX version

    $ oslevel -s 6100-08-03-1339

    MQ version

    (0)mqm@rs6stech02:/home/mqm: dspmqver Name: WebSphere MQ Version: 7.0.1.7 CMVC level: p701-107-111117 BuildType: IKAP - (Production)

    Perl installation

    $ perl -V Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=aix, osvers=5.3.0.0, archname=aix-thread-multi uname='aix akash79 3 5 00011a85d600 ' config_args='-desr -Dinstallprefix=/usr/opt/perl5 -Dprefix=/usr/op +t/perl5 -Dcc=xlc_r -Duseshrplib -Dusethreads' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemulti +plicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc_r', ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURC +E -qmaxmem=-1 -qnoansialias -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT - +q32 -D_LARGE_FILES -qlonglong', optimize='-O', cppflags='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem= +-1 -qnoansialias -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT' ccversion='9.0.0.2', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='ld', ldflags =' -brtl -bdynamic -b32' libpth=/lib /usr/lib /usr/ccs/lib libs=-lbind -lnsl -lgdbm -ldbm -ldb -ldl -lld -lm -lcrypt -lpthrea +ds -lc -lbsd perllibs=-lbind -lnsl -ldl -lld -lm -lcrypt -lpthreads -lc -lbsd libc=, so=a, useshrplib=true, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_aix.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -bE:/usr/ +opt/perl5/lib/5.8.8/aix-thread-multi/CORE/perl.exp' cccdlflags=' ', lddlflags='-bhalt:4 -bexpall -G -bnoentry -lpthrea +ds -lc' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API Built under aix Compiled at Jun 2 2009 16:11:40 @INC: /usr/opt/perl5/lib/5.8.8/aix-thread-multi /usr/opt/perl5/lib/5.8.8 /usr/opt/perl5/lib/site_perl/5.8.8/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.8.8 /usr/opt/perl5/lib/site_perl

    Can you please help me identify where I have gone wrong or offer me a workaround ?

Can you offer me some tips on this module?
1 direct reply — Read more / Contribute
by Anonymous Monk
on Aug 27, 2014 at 11:25
    Dear friends,
    I am trying to use the following module in a project of mine...
    https://metacpan.org/pod/Bio::Graphics::DrawTransmembrane

    It works fine, but I was wondering, is there a way that I can tilt the bars to have an angle, instead of being vertical?
    My code, based on the module, which uses GD-graph, is the following:
    use DrawTransmembrane; $topology_final = 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII +IIIIIIIII0IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII +IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIMMMMMMMMMOOOOO +OOOOOOOOOOMMMMMMMIIIMMMMMMMMMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOMMM +MMMMMMIIIMMMMMMMMMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOMMMMMMMMMIIIIIIIMMMM +MMMMMMMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOMMMMMMMMMMMIIIMMMMMMMMMMMOOOO +OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOMMMMMMMMMMMIIIIIMMMMMMMMMOOOOOOOM +MMMMMMMMMMIIIMMMMMMMMMMMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOMMMMMM +MMMMMIIIIMMMMMMMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOMMMMMMMMMIIIMMM +MMMMMMMMOOOOOOOOOOOOOOMMMMMMMMMMMIIIIIMMMMMMMMMOOOOOOOOOOOOOOOOOOOOOO +OOOOOMMMMMMMMMMMIIIMMMMMMMOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOMMM +MMMMMM'; @total_top = (); if($topology_final=~/M/) { while ($topology_final =~/(.)\1*/g) { if ($1 eq "M") { my $start_TM = $-[0] + 1; my $end_TM = $+[0]; push @total_top, $start_TM; push @total_top, $end_TM; } } my $image = DrawTransmembrane->new ( -title=>"topology prediction image", -n_terminal=>'in', -topology=>\@total_top, -bold_helices=> 1, -bold_labels=>1, -text_offset=>-25, -helix_label=>'b', -outside_label=>'Extracellular', -inside_label=>'Periplasm', -membrane_label=>'Membrane', -helix_width=>30, -vertical_padding=>150, -horizontal_padding=>120, -n_terminal_offset=>50, -n_terminal_height=>220, -c_terminal_offset=>30, -c_terminal_height=>220, -helix_label=>'Sheet', -colour_scheme=>'yellow' ); open (OUTPUT, '>', 'test.png'); binmode OUTPUT; print OUTPUT $image->png; close (OUTPUT); }

    Any tips would be greatly appreciated... The goal should be to tilt the bars a bit, like, e.g. in:
    http://bioinformatics.biol.uoa.gr/TMRPres2D/screens/big4.png
Setting syslog layout with log4perl
1 direct reply — Read more / Contribute
by neilwatson
on Aug 27, 2014 at 10:52

    Greetings

    This is my first dive in log4perl. I'm trying to configure for syslog, but I get the error ERROR: trying to set layout for SYSLOG to '%-5p %C - %m%n'. What is the correct way to configure the layout?

    log4perl.rootLogger=DEBUG, SYSLOG log4perl.appender.SYSLOG = Log::Dispatch::Syslog log4perl.appender.SYSLOG.min_level = debug log4perl.appender.SYSLOG.ident = logging.pl log4perl.appender.SYSLOG.facility = daemon log4perl.appender.SYSLOG.layout = %-5p %C - %m%n

    Neil Watson
    watson-wilson.ca

CGI files and Dancer coexisting?
2 direct replies — Read more / Contribute
by einhverfr
on Aug 27, 2014 at 04:59
    Hi;

    I am trying to write some scaffolding to support moving LedgerSMB to Dancer. Unfortunately I have had very little success at first. I tried to use Dancer::Plugin::FakeCGI and got errors during the import process. Tracing these, it looks like the module does not work with recent versions of HTTP::Headers.

    So I am wondering if this is even the right way to go about things. Should I try to run these perhaps as different PSGI apps under the same app.psgi and use work I have done to run the old cgi apps under Starman and FCGI instead? Is there another option I haven't thought of?

    I am mostly looking for strategic help and a pointer in the right direction.

Hygienic eval of templates with perl code?
1 direct reply — Read more / Contribute
by LanX
on Aug 26, 2014 at 23:28
    Hi

    I have the feeling of reinventing the wheel and would like to see other solutions...

    I'm evaling code text which is composed of 2 snippets which are supposed to be correct in isolation.

    Take as example using B::Deparse to back engineer a functions code and then wrapping new code around it before evaling. (something like this is shown in the Perl Hacks book)

    Now this additional code could contain new symbols (identifiers) like variables, subnames or labels which might shadow equally named symbols in the original code.

    This is known as Hygiene Problem.

    I decided to solve this with a template system where new symbols need to be placeholders, which are renamed (extended with a suffix) if they conflict with old symbols.

    Did anybody already try to solve this on CPAN?

    I'd like to compare different approaches.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-08-29 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls