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

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
Firefox/Javascript/Perl CGI argument passing issue
4 direct replies — Read more / Contribute
by beckmanel
on Jul 22, 2014 at 10:40

    I'm using CGI::Application::Dispatch on the Perl backend

    Data is sent from Javascript:

    88 var _factories = [ 89 function() { return new XMLHttpRequest(); }, 90 function() { return new ActiveXObject("Msxml2.XMLHTTP"); } +, 91 function() { return new ActiveXObject("Microsoft.XMLHTTP") +; } 92 ]; 93 94 var _factory = null; 95 96 function newRequest() { 97 if (_factory != null) return _factory(); 98 99 for(var i = 0; i < _factories.length; i++) { 100 try { 101 var factory = _factories[i]; 102 var request = factory(); 103 if (request != null) { 104 _factory = factory; 105 return request; 106 } 107 } 108 catch(e) { 109 continue; 110 } 111 } 112 _factory = function() { 113 throw new Error("XMLHttpRequest not supported"); 114 } 115 _factory(); 116 } 1233 var http_request; 1234 http_request = newRequest(); 1252 var query = "ip=" + document.getElementById('ip').value; 1253'POST', "/", t +rue); 1254 http_request.send(query); 1255 return false;

    But when I do the same action from the same web page, but different browsers, I get parameters in a different form through Perl CGI (see below). My code has been working with the IE form, can I do anything to make the Firefox output form similar ?

    THANKS Much in advance.

    The below was generated in the target Perl procedure by:

    print STDERR "QUERY: ", Dumper($self->query), "\n";

    FIREFOX 15202 [Tue Jul 22 08:55:55 2014] [error] [client] QUERY: + $VAR1 = bless( {, referer: 15203 [Tue Jul 22 08:55:55 2014] [error] [client] + '.parameters' => [, referer: 15204 [Tue Jul 22 08:55:55 2014] [error] [client] + 'POSTDATA', referer: http://56.207.201. +210:8083/ 15205 [Tue Jul 22 08:55:55 2014] [error] [client] + ],, referer: 15206 [Tue Jul 22 08:55:55 2014] [error] [client] + '.charset' => 'ISO-8859-1',, referer: +0:8083/ 15207 [Tue Jul 22 08:55:55 2014] [error] [client] + 'POSTDATA' => [, referer: 15208 [Tue Jul 22 08:55:55 2014] [error] [client] + 'ip=', referer: http://56.207. +201.210:8083/ 15209 [Tue Jul 22 08:55:55 2014] [error] [client] + ],, referer: 15210 [Tue Jul 22 08:55:55 2014] [error] [client] + '.fieldnames' => {},, referer: 15211 [Tue Jul 22 08:55:55 2014] [error] [client] + 'escape' => 1, referer: 15212 [Tue Jul 22 08:55:55 2014] [error] [client] + }, 'CGI' );, referer: 15213 [Tue Jul 22 08:55:55 2014] [error] [client] , refe +rer: 15214 [Tue Jul 22 08:55:55 2014] [error] [client] [Tue J +ul 22 08:55:55 2014] Use of uninitialized value in pattern +match (m//) at /var/www/smartncm_test_ie11/lib/OpenNCMApp/EntryPoint. +pm line 896., referer: 15215 [Tue Jul 22 08:55:55 2014] [error] [client] [Tue J +ul 22 08:55:55 2014] Use of uninitialized value in pattern +match (m//) at /var/www/smartncm_test_ie11/lib/OpenNCMApp/EntryPoint. +pm line 897., referer: IE 15332 [Tue Jul 22 08:58:58 2014] [error] [client] QUERY: + $VAR1 = bless( {, referer: 15333 [Tue Jul 22 08:58:58 2014] [error] [client] + '.parameters' => [, referer: 15334 [Tue Jul 22 08:58:58 2014] [error] [client] + 'ip', referer: +83/# 15335 [Tue Jul 22 08:58:58 2014] [error] [client] + ],, referer: 15336 [Tue Jul 22 08:58:58 2014] [error] [client] + '.charset' => 'ISO-8859-1',, referer: +0:8083/# 15337 [Tue Jul 22 08:58:58 2014] [error] [client] + 'ip' => [, referer: 15338 [Tue Jul 22 08:58:58 2014] [error] [client] + '', referer: +083/# 15339 [Tue Jul 22 08:58:58 2014] [error] [client] + ],, referer: 15340 [Tue Jul 22 08:58:58 2014] [error] [client] + '.fieldnames' => {},, referer: +# 15341 [Tue Jul 22 08:58:58 2014] [error] [client] + 'escape' => 1, referer: 15342 [Tue Jul 22 08:58:58 2014] [error] [client] + }, 'CGI' );, referer: 15343 [Tue Jul 22 08:58:58 2014] [error] [client] , refe +rer:
out of memory issue while creating very large xml file using XML::Simple
3 direct replies — Read more / Contribute
by perlCrazy
on Jul 22, 2014 at 06:51
    How we can create very large xml file(1 GB) using XML::Simple module.
    variable $tableDetailsRef is ref of hash, will hold very large blob. While using with xmlout causing memory issue. Host is RHEL6 and memory available is 36 GB. I am using below code:
    #this variable will hold very large complex data structure. my $tableDetailsRef = {}; my $xmlFile = "test_name.xml"; my $targetNameStr = "target-name"; #Creating object for xml file my $xmls = XML::Simple->new( RootName => undef, ForceArray => ['tables'], KeyAttr => { table => 'id' }, ); my $contents = {}; $contents->{dspl}->{targetNamespace} = "string_test"; ################################################ if(defined $tableDetailsRef){ push @{ $contents->{dspl}->{'tables'} }, { table => $tableDetailsRef, }; } #################################################### ##Generate the xml file eval { $xmls->XMLout( $contents, xmldecl => '<?xml version="1.0" encoding="UTF +-8" standalone="no" ?>', OutputFile => $xmlFile ); }; if($@) { print "Exception: Could not xml file : $xmlFile, Error-$@"); }
I wrote a script to grep
2 direct replies — Read more / Contribute
by ksr19742001
on Jul 22, 2014 at 06:47
    Hi All, I wrote a following script

    1. To read the file and grep the scpecific line.

    My requirement is to if that line exceeds it should print that information.
    #C:/Dwimperl/perl/bin #To Open the file open (MYFILE,"C:/Users/katragas/Desktop/apadmin_get_status_log.txt"); if (grep {/Response Queue Size: 0/} <MYFILE>){ print "Yes, it is\n"; }else{ print "nope, it's not\n"; } close (MYFILE)
    I am sure, I am doing mistake here. Can some one help to get it moving.
DB_File, windows and
2 direct replies — Read more / Contribute
by Arthfael
on Jul 22, 2014 at 06:11

    Hi monks!

    I am trying to use a script which uses Bio::SeqIO and Bio::Seq, so I tried to install Bioperl on my Windows 8.1 machine. However, before this I have to install the module DB_File, and that's where my trouble starts:

    I have installed Berkeley DB 4.3.29, but DB_File's install is failing, and apparently for it to work I have to edit the "" file (see ). I have been unsuccessful however, as each time I attempt I get an "access denied" message. Can one of you monks tell me how I can circumvent this?

String extract
1 direct reply — Read more / Contribute
by kepler
on Jul 22, 2014 at 05:03
    Hi, I'm trying to extract an expression from a line. Here's what I'm doing: codemy $exp = $line =~ m/FAR PASCAL_CONV\ (.*)\(/gi;\code with $1 I get the expression I want, but also the sring PASCAL ! The $line exp is of the type: FAR PASCAL what_i_want(etc...) or FAR PASCAL_CONV what_i_want(etc...) What am I doing wrong...? Kind regards, Kepler
count number of lines with +
3 direct replies — Read more / Contribute
by ladnjay
on Jul 22, 2014 at 04:51
    Can anyone show me how to write a script to count the number of lines starting with a "+" sign. It should be starting with a plus and followed by a space.
print package's symble table
4 direct replies — Read more / Contribute
by vinoth.ree
on Jul 22, 2014 at 04:06

    Hi Monks,

    I was doing somthing wrong, pls help me on this.

    I was trying to print the symble table of a package of mine.below is my package code

    package Vinoth; use strict; use warnings; use Data::Dumper; our $VERSION=1.0; sub printSimbleTable{ my $package = shift; print "I am in printSimbleTable of : $package\n"; print Dumper \%$packge::; #Not working print Dumper \%Vinoth::; # Works #print Dumper \%{$packge}::; #Not working # foreach my $varName (sort keys %$package::) # { # print "$varName\n"; # local *typeglob = %{$package}::{$varName}; # print "$$varName\n" if ($typeglob); # } } 1;

    I tried to use this package in a perl script and calling a function in this module to print the package's symble table. Below is the script file

    use strict; use warnings; use Vinoth; &Vinoth::printSimbleTable( 'Vinoth' );

    As you can see this line print Dumper \%$packge::; #Not working the $package hash my module name 'Vinoth', but its not printing the symble table with the Dumper, when I replace it with the my module name explicity, it works. how to use $package variable here and make it work ?


    Packages and Symbol Tables

    A package's namespace is a symbol table. The name of your package is stored in a hash named after your package with two colons appended to it. If you name a package BushWhack, its symbol table name is %BushWhack::. Packages are represented as %main:: or %:: in the symbol table by default. Since we're dealing with a hash, each key must have a value. Because keys are identifiers, values are the corresponding typeglob values; globs are pretty efficient because they do the symbol table lookups at compile-time. In other words, *BushWhack represents the value of %BushWhack::--see the following:

    local *low_flyer = *BushWhack::variable; # compile time local *low_flyer = *BushWhack::{"variable"}; # run time

    You can look up all the keys and variables of a package with this example. You may use undef() on these to clear their memory, and they will be reported as undefined. You shouldn't undefine anything here unless you don't plan to load these packages again. Because the memory has already been filled, it saves time when you load them if you leave them defined:1

    foreach $symbol_name (sort keys %BushWhack::) { local *local_sym = $BushWhack::{$symbol_name}; print "\$$symbol_name is defined\n" if($local_sym); print "\@$symbol_name is defined\n" if(@local_sym); print "\%$symbol_name is defined\n" if(%sym); }

    All is well
foreach loop and creating files with "$_"
7 direct replies — Read more / Contribute
by james28909
on Jul 21, 2014 at 23:08
    ok i originally answered my own question this time. i wanted to make any prespecified number of files with a foreach loop (or for loop, i dont think it matters much). I accomplished that with this code and didnt have to ask :
    my $file = "file"; my $temp = "temp"; foreach (1..5){ open $file, '>', "$temp$_"; print $file "THIS IS DATA"; }

    now my next question is, i have been reading around here and there about this special variable "$_" and come across this thread Here and it say to try to avoid this special variable. in the code above, it was my very first time to even try using it tbh, could someone explain to me why it should be avoided in the case of my code above? or is it ok? or what would be a better solution to it?
Bioinformatics- Use of uninitialized value
4 direct replies — Read more / Contribute
by mlsmit10
on Jul 21, 2014 at 17:25

    Hi, guys. I've posted previously about this particular script, but I've recently run into a new problem with it. When running the script, I receive the following error: Use of uninitialized value $_ in pattern match (m//) at /Users/smithcabinets26/Desktop/RAD/Digester/Improving/ line 66.

    This is line 66:

    my @third_fragments = grep !/$rsite3/, $second_fragments[$i];

    The script takes a genome, cuts it at two restriction sites, excludes fragments containing a third site, and tells me how many fragments are present in particular size ranges. Line 6 works to remove the fragments with the third site present. The script seems to be functioning correctly, but I am not sure why the above error would occur and am worried that it may be affecting my output in some way. Thanks in advance for your help. The entire script is below.

Undefined value as a symbol reference
3 direct replies — Read more / Contribute
by link867
on Jul 21, 2014 at 16:12

    I have been having the hardest time with the open function on the server I am coding. I had no problem with it on my VM but because of restrictions of the proxy server I have to use a server to script. This is the output of perl -v: This is perl, v5.8.0 built for i586-pc-sco3.2v5.0 and unname -a: SCO_SV 3.2 5.0.7 i386 I keep getting Can't use an undefined value as a symbol reference at ./ line 97 Here is the problem sub:

    sub getComment { my $switchIp = $_[0]; my $INFILE; open ($INFILE, 'templateHosts' ) or die "can't open file $!"; my @hostsText = <$INFILE>; my $hostsLine = "";
    I have also tried different ways :
    open ($INFILE, '<', 'templateHosts') open ($INFILE, '< templateHosts') open $INFILE, '<templateHosts')
    Thanks for any help!

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (17)
    As of 2014-07-23 13:21 GMT
    Find Nodes?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:

      Results (144 votes), past polls