Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Seekers of Perl Wisdom

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

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
Use CGI to run a Perl script via web server
5 direct replies — Read more / Contribute
by suvajit123
on May 25, 2017 at 07:07

    Hello Monks

    I have created a Perl script which runs fine manually with a value parsed during runtime, i.e. like 'perl value'

    I need to execute this over a Web Server (IBM HTTP Server), I have configured it correctly and it is able to execute the program to display Hello World with a name given as input in the URL. like

    But my actual code which calls for a different Perl script from this, does not work.

    #!/usr/bin/perl use strict; use CGI; use IPC::System::Simple qw(system capture); #create CGI query object to get the SSO from URL my $sso = new CGI; my $sso = $query->param( "sso" ); #*********Script within a script both files in same path********** system( "perl $sso" ); print "Content-type:text/html\r\n\r\n"; print "<html>"; print "<head>"; print "<title>Some Header</title>"; print "</head>"; print "<body>"; print "<h2>You have entered $sso</h2>"; print "</body>"; print "</html>";

    This is not working as it is not detecting IPC::System::Simple qw(system capture) from this script. How could I make the CGI parse the $sso to ?

    Thanks in advance....

Regex problem
2 direct replies — Read more / Contribute
by dazz
on May 25, 2017 at 05:35
    I download a web page that includes data used and remaining data for a mobile connection.
    I want to find the two values and convert them from strings to values.

    A snippet of the html page is:
    <span class="remaining-data">54MB used</span> <span class="expires-data-right-align">1.44GB remaining</span>
    I use the regex to get a matching substring with the 1st value within
    (my $DataUsed) = $stgUsed =~ /"remaining-data">([+-]?(\d*\.)?\d+)(MB +|GB) used/; # trying to get just the digits. (my $unit) = $stgUsed =~ /(MB|GB)/; # match either MB or GB if ( $unit eq "GB"){ $DataUsed *= 1000; }
    The output in $stgUsed is what I expect:
    DB<5> x $stgUsed 0 'class="remaining-data">315MB'
    In want to capture just the number (315) and the units (MB) but $DataUsed in undef.
    I have tried using $1,$2 ... but they are undef as well.

    How to I get the digits substring and the MB/GB substring????

Undefined Subroutine error
3 direct replies — Read more / Contribute
by pdahal
on May 25, 2017 at 05:34

    hello monks! Below I have posted my code. I am getting an error which says "Undefined subroutine &main::fields called at line 34, <$data> line 2." Can anyone help me?

    #Written by Prasuna Dahal use warnings; use XML::Simple; use LWP::UserAgent; use HTTP::Request::Common; use URI::Escape; use Text::CSV; use Data::Dumper; my $i = 0; my @keystr; my @kwrds = {"inhibitors", "activity", "complex", "activator", "activi +ty", "activities", "activated", "proteins", "deficiency", "levels", " +functions", "reductions", "protease", "proteases"}; my $file = "proteinlist.csv"; my $ua = LWP::UserAgent->new; my $csv = Text::CSV->new({sep_char => ','}); #Open the result in a CSV file open (my $fh, ">", "test1.csv"); print $fh "Valid Proteins\n"; #open file containig protein_name #open(my $data1, '<', "proteinlist.csv"); #Open the file containing the PubMed IDs open(my $data, '<', "test.csv"); while (my $line = <$data>) { chomp $line; if ($csv->parse($line)) { #Skip 1st line next if ($. == 1); my @fields = $csv-fields(); #Replace (-) with (,) $fields[0] =~ tr/-/,/; my $id = $fields[0]; #Initialize http request my $args = "db=pubmed&id=$id&retmode=text&rettype=abstract"; my $req = new HTTP::Request POST => 'https://eutils.ncbi.nlm.nih.g +ov/entrez/eutils/efetch.fcgi'; $req->content_type('application/x-www-form-urlencoded'); $req->content($args); #Get response my $response = $ua->request($req); my $content = $response->content; $fields[0] =~ tr/,/-/; my @abstract = split (/[.]/, $content); for $abstract(@abstract){ @var1 = split ((/[ ]|[,]/), $abstract); foreach $var1(@var1){ open(my $data1, "<", $file); while (my $line1 = <$data1>) { chomp $line1; my @fields1 = split ",", $line1; $keystr[$i] = $fields1[0]; $i++; if ($var1=~ /\b$keystr[$i]\b/i){ foreach $kwrds(@kwrds){ if ($var1=~ /\b$kwrds\b/i){ my $valid_prot = $var1; } } print $fh "$valid_prot\n"; print "$valid_prot\n"; } } } } } } close($fh);
Tcl::Tk exit
2 direct replies — Read more / Contribute
by Sandy
on May 24, 2017 at 15:03
    Really silly question.

    I am used to Perl/Tk, with sample code that looks like

    use Tk; my $mw = MainWindow->new(-title=>"hello world"); $mw->Label(-text=>"hello")->pack(); $mw->Button(-text=>"Exit",-command=>sub{exit})->pack(); MainLoop;

    Now I am updating (?) to Tcl::Tk (because Perl/Tk requires Quartz on my Mac)

    use Tcl::Tk; my $int = new Tcl::Tk; my $mw = $int->mainwindow; $mw->Label( -text => "Hello World!" )->pack(); $mw->Button( -text => "Exit", -command => sub { exit } )->pack(); $int->MainLoop;

    But when I exit, I get the following error message (and a segmentation fault)

    perl5.18 quit unexpectedly while using the Tk plug-in.

    I have tried combinations of $mw->exit(), but that also doesn't work.


Supervised machine learning algo for text matching across two files
4 direct replies — Read more / Contribute
by Anonymous Monk
on May 24, 2017 at 15:01
    Hey monks,

    I need some help thinking through what type of algorithm I need to build and some suggestions on the best way to do it in Perl.

    I've got two files and the objective is to match the rows in file 1 with an ID in a row in file 2.

    File 1 has millions of rows and about 55 fields, but there is no one field that is capable of matching to anything in file 2 directly, despite in the real-world there being a very real 1:1 mapping for each row. From manual matching efforts of content experts I have a list of about 15% matched but the method to do this cannot be used any further thus I would like to use this 13% as a training set to build a machine learning algorithm that could help match the rest. I am thinking the right algorithm type is a multi-class classifier.

    My hypothesis is that throughout the 15% matched there are patterns that are not easy to see that an algorithm like a decision forest or something could help to tease out and help get the match rate from 15% up to 30% etc...

    Any comments or suggestions are tremendously helpful. Cheers!

Hash user input
3 direct replies — Read more / Contribute
by Nansh
on May 24, 2017 at 13:14

    Hello I have two hash say %hash1 and %hash2

    %hash1 and %hash2 these hash contains some keys and values

    I need to give these hash as a user input

    my %hash_input=@_; my %hash_input2=@_;
    can i take two hash as a user input like i mentioned above??? Thanks in Advance.
Best way to sum an array?
9 direct replies — Read more / Contribute
by Anonymous Monk
on May 24, 2017 at 11:06
    How do I pick the "best way" to do something? In particular, I want the fastest way, using the fewest resources, to sum up the values in an array of arbitrary length. I could do it in a loop with a bucket, I could do it recursively, I could do it with a join and an eval, etc. What's the "best" way? Is there a "better" way? How do I measure? How do I pick?
    # Iterative sub SumArryItr { my $agg = 0; $agg += $_ for @_; return $agg } # Recursive use feature 'current_sub'; sub SumArryRcs { 1==@_?$_[0]:1>@_?die:shift(@_)+__SUB__->(@_) } # Eval Trick sub SumArryEvl { eval join "+", @_ } # Test my @array = ( -249, 0, 74, 65, 80, 72 ); print "Sum: ", join( ", ", @array ), "\n"; print "Itr: ", SumArryItr( @array ), "\n"; print "Rcs: ", SumArryRcs( @array ), "\n"; print "Evl: ", SumArryEvl( @array ), "\n";
XML-LibXML-2.0129 installation issues
2 direct replies — Read more / Contribute
by Brat
on May 24, 2017 at 10:44
    I installed the latest libxml perl library XML-LibXML-2.0129 after downloading it from cpan. my installation did not seem to have gone fine.
    perl Makefile.PL FORCE=1 PREFIX=/app/localapps/perl/lib LIB=/app/localapps/perl/lib enable native perl UTF8 running xml2-config...failed The installed version of libxml2 FORCED 2.9.4 is not compatible with XML::LibXML (and probably buggy)! You may continue at your own risk using 'perl Makefile.PL FORCE=1', bu +t: - don't expect XML::LibXML to build or work correctly! - don't report errors! - don't send patches! Check the README file for more information on versionsthat are tested +with XML::LibXML Checking for ability to link against xml2...yes Generating a Unix-style Makefile Writing Makefile for XML::LibXML Writing MYMETA.yml and MYMETA.json

    The issue with the installation is that I cannot find Not sure How I can fix this. Please help. what am I missing?

Getting JSON::PP:Boolean value
2 direct replies — Read more / Contribute
by cormanaz
on May 24, 2017 at 08:42
    Good Day bros. I have some values in a json file parsed with mod JSON that have values JSON::PP:Boolean. How do I process these to get the true/false value? If I just assign them to another variable they are undef.
extract column data
3 direct replies — Read more / Contribute
by bigup401
on May 24, 2017 at 07:35

    am trying to extract data from column. but am only getting the first lastname am not getting the reset. i only get john

    +----------+ | lastname | +----------+ | john | | Doe | | Jones | | Smith | +----------+
    my $sth = $dbh->selectrow_array("SELECT lastname FROM dbase"); $dbh->disconnect; #its ok with array @data = $sth1; print @data;

Add your question
Your question:
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.
  • Log In?

    What's my password?
    Create A New User
    [shmem]: karlgoethebier: es ist theologisch umstritten, ob jesus an christi himmelfahrt tatsächlich besoffen und mit bollerwagen zu seinem vater aufgebrochen ist
    [karlgoethebier]: shmem: Ja ischweis
    [karlgoethebier]: shmem: Vielleicht hat er in den Bollerwagen gebrochen?
    [karlgoethebier]: shmem:Ach so. Bollerwagen ist eigentlich was für Kinder. Bei uns fahren sie mit Traktoren und Feuerwehrwagen rum...
    [shmem]: karlgoethebier: here abouts people are sitting in big tents, gulp beer and ingest badly scorched chicken and sausages while (not) listening to afwul musik

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (13)
    As of 2017-05-25 12:39 GMT
    Find Nodes?
      Voting Booth?