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

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
Installation failure for Net::Pcap PM
1 direct reply — Read more / Contribute
by waytoperl
on Aug 30, 2014 at 04:49

    Installation failed for Net::Pcap. Warnings mentioned in build.log about not available of list of functions. There are 17 warnings and i'm not able to proceed without installing Net::Pcap, please help.

    ./stubs.inc:187:2: warning: "the function pcap_list_datalinks() is not + available" [-W#warnings] #warning "the function pcap_list_datalinks() is not available"
    ./stubs.inc:322:2: warning: "the function pcap_createsrcstr() is not a +vailable" [-W#warnings] #warning "the function pcap_createsrcstr() is not available"
    17 warnings generated. rm -f blib/arch/auto/Net/Pcap/Pcap.bundle LD_RUN_PATH="/usr/lib" env MACOSX_DEPLOYMENT_TARGET=10.3 cc -bundle - +undefined dynamic_lookup -fstack-protector Pcap.o -o blib/arch/auto/ +Net/Pcap/Pcap.bundle \ -lpcap \ chmod 755 blib/arch/auto/Net/Pcap/Pcap.bundle /Users/....../perl5/perlbrew/perls/perl-5.20.0/bin/perl -MExtUtils::Co +mmand::MM -e 'cp_nonempty' -- Pcap.bs blib/arch/auto/Net/Pcap/Pcap.bs + 644 cp bin/pcapinfo blib/script/pcapinfo /Users/....../perl5/perlbrew/perls/perl-5.20.0/bin/perl -MExtUtils::MY + -e 'MY->fixin(shift)' -- blib/script/pcapinfo Manifying blib/man1/pcapinfo.1 Manifying blib/man3/Net::Pcap.3 Running Mkbootstrap for Net::Pcap () chmod 644 Pcap.bs PERL_DL_NONLAZY=1 /Users/......../perl5/perlbrew/perls/perl-5.20.0/bin +/perl "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test:: +Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t # Testing Net::Pcap 0.17 (libpcap version 1.3.0 - Apple version 41) un +der Perl 5.020000
intersection of scalar with 1D array and 2D array Matlab=>Perl
2 direct replies — Read more / Contribute
by f77coder
on Aug 29, 2014 at 22:58
    Hello,

    I'm converting some Matlab code into perl. Here's the Matlab code.

    while ~feof(fileIDS); m1=fgetl(fileIDS); [a,b]=intersect(dataD{1},{deblank(m1)}); if (~isempty( a)) data=dataD{2}(b); elseif(~isempty(intersect(dataT{1},{deblank(m1)})) ) data=1.0; else data=0.0; end; end;

    dataD is a 2D array, dataT is a 1D array

    m is a scalar value read from a file

    a=returns index if there is one and null if it doesn't and b=value at index a

    Basically what this does is the following

    intersection (2D data,scalar) if intersection exists not null a=index of location data= value of location at b elseif intersection (1D data,scalar) data=1.0 else data=0.0 endif

    I'm reading through this http://perldoc.perl.org/perlfaq4.html#How-do-I-test-whether-two-arrays-or-hashes-are-equal%3f but this assumes that the arrays are of equal dimensions (1D).

    I'd like to know what is the simplest and fastest way?

    use 5.12.0; use strict; use warnings; use diagnostics; use List::MoreUtils; open my $TEST, '<', $f_Test or die "Could not open=> $f_Test : $!"; my $data; while (my $scalar=<$TEST>) { chomp($scalar); [my $a, my $b]=firstidx { $_ == $scalar } @arrayPFA; if(!exists $a) { $data=$arrayPFA[$b]; } elsif(if any { ! defined($scalar) } @arrayT;) { $data=1.0; } else { $data=0.0; }; }; close $TEST

    Thanks for any help.

How do they combine two perl scripts together?
1 direct reply — Read more / Contribute
by Anonymous Monk
on Aug 29, 2014 at 21:19

    #1 I downloaded the script from http://forums.bzflag.org/viewtopic.php?f=40&t=12886

    I used google and found at http://www.tutorialspoint.com/perl/perl_cgi.htm how they Pass Text Area Data to CGI Program but, I am missing the info on how the web master of the webpage at http://d41games.freehostia.com/stuff/telefixerinput.html combied the two perl scripts together.

    Thank you for any help.

Error hash declaration
2 direct replies — Read more / Contribute
by sidsinha
on Aug 29, 2014 at 20:05

    A fairly simple code to load a file into a hash of keys and values. I declared my hash before the while loop globally, but when I try to use $hashofstates->($key) = $val; it throws me an error as if it wasnt declared. What could possibly be wrong?

    use strict; use warnings; use Data::Dumper; my $File = "inp.txt"; open FILE, '<' , $File or die $!; my %hashofstates; while (my $line=<FILE>) { chomp $line; my ($key, $val) = split /\s+/, $line ,2; $hashofstates->($key) = $val; } close FILE or die 'Could not close file'; print (values \%hashofstates);

    Error:

    perl prog.pl Global symbol "$hashpfstates" requires explicit package name
Digging through HTML Formatting with HTML::TagParser
1 direct reply — Read more / Contribute
by JayBee
on Aug 29, 2014 at 17:18
    I've been trying to use HTML::TagParser to pull reviews from Yelp and modifying formatting slightly to post on our website, though I'm having difficulty parsing through child nodes of the HTML. So I started a basic html file to play with, and still having some difficulty getting the beginning and ending tags to encapsulate properly with inner-text. Here's the basic version of my HTML
    <table> <tr id="row1"> <td><div id="r1d1"><b>Test11</b></div></td> <td><div id="r1d2"><i>Test12</i></div></td> <td><div id="r1d3">test13</div></td> <td><b>test14</b></td> </tr> <tr id="row2"> <td><div id="r2d1"><b><em>Test21</em></b></div></td> <td>2</td> <td>3</td> <td>4</td> </tr> </table>
    and my code, which pulls things out of place since I can't seem to get my mind to grasp the structuring correctly. Certainly I'm missing something about the "parentNode" after a "childNode" is found... and perhaps "nextSibling" can be useful somewhere.
    #!/usr/bin/perl use strict; use CGI ':standard'; use HTML::TagParser; my @Body; my $html=HTML::TagParser->new('table.txt'); my @elem=$html->getElementsByTagName("table"); foreach my $parent(@elem){ my $text=$parent->innerText(); my $tag=$parent->tagName; my $get=$parent->childNodes(); if (@$get){push @Body,digChild(@$get);} push @Body,"<$tag>$text</$tag>"; } #foreach parent print header,start_html('table'); print join("\n",@Body)."\n"; print end_html; sub digChild { my @ar=@_; foreach my $row(@ar){ my $tag=$row->tagName; my $txt=$row->innerText; my $c=$row->childNodes(); if (@$c){push @Body,digChild(@$c);} return "<$tag>$txt</$tag>"; } # foreach row } # sub
    Thank you.
connect to Oracle with DBI
1 direct reply — Read more / Contribute
by fionbarr
on Aug 29, 2014 at 15:09
    use strict; use warnings; apologies if this is duplicate
    use DBI; my $host = "yyy.xxx.com"; my $user = "user"; my $password = "password"; my $dbh = DBI->connect("dbi:Oracle:host=$host;sid=orcl;port=7010", $user, $password, { RaiseError => 1, AutoCommit => 0 }) +;
    I am getting the error:
    TNS:listener does not currently know of SID in connect descriptor
Need to send an email through my SMTP server using Perl
1 direct reply — Read more / Contribute
by Logic_Bomb421
on Aug 29, 2014 at 14:37

    So like the title says, I need to send an email via my SMTP server. It's just a simple test email designed to verify the SMTP server is active and doing its job. Here's what I have so far (with email addresses removed):

    #!/usr/bin/perl use lib "/path/to/Net::SMTP/module"; use Net::SMTP $host = "SMTP SERVER"; $port = 25; $smtp = Net::SMTP->new($host, Hello => port=>$port) $smtp->mail("FROM EMAIL ADDRESS"); $smtp->recipient("TO EMAIL ADDRESS"); $smtp->data; $smtp->datasend("From: host\@domain.com"); $smtp->datasend("To: account\@domain.com\n"); $smtp->datasend("Subject: Test"); $smtp->datasend("\n"); $smtp->datasend ("This is a test"); $smtp->dataend; $smtp->quit;

    When I run this, I get the error:

    "SMTP SERVER" is not exported by the Net::SMTP module. Can't continue +after import errors at line 6.

    What does it mean "is not exported"?

Google spreadsheet copy/paste?
1 direct reply — Read more / Contribute
by AllPaoTeam
on Aug 29, 2014 at 12:05

    good morning Perl Monks, I am looking for a more efficient way to write this code. I am copying huge amount of data from Excel spreadsheet with multiple tabs into a Google spreadsheet with multiple tabs but it takes a long time because I am updating it cell by cell, is there a way I can copy the whole worksheet/range of cells and paste it into Google spreadsheet? To make it easier for me, I converted the spreadsheet into cvs files. Any help would be greatly appreciated. Below is the code I am using:

    Nevermind.... I found the batchupdate_cell which is alot faster. Sorry..

Apache::RequestNotes in mod_perl 2.0
1 direct reply — Read more / Contribute
by ait
on Aug 29, 2014 at 10:54

    Hi

    I noticed that Apache::RequestNotes doesn't seem to be available for Apache2 so I am guessing that this functionality was incorporated in mod_perl 2.0 natively?

    If so, would someone kindly point me to an example on how to do this exact same thing with mod_perl 2?

    I need something very early in the request that parses form data and then make it avail to the rest of the request. My current solution involves a PerlTransHandler that slurps the content, parses it and saves it to notes. Then I have to re-inject the raw content back with a PerlInputFilterHandler so it's avail for the rest of the request chain.

    I hate re-inventing the wheel and I think something like Apache::RequestNotes would really be more elegant for what I'm trying to do.

    Many thanks in advance!

Rename filenames in perl using regex
3 direct replies — Read more / Contribute
by ArifS
on Aug 29, 2014 at 10:37
    I would like to replace a bunch of filenames from- "MY.switch._Org.1st.txt" "router.-2nd.Org.MY.txt" "3rd.switchmy-org.txt" to, something like as following with all uppercase- "1ST.SWITCH.MY.ORG.TXT" "2ND.ROUTER.MY.ORG.TXT" "3RD.SWITCH.MY.ORG.TXT" Any suggestion will be greatly appreciated.....

Add your question
Title:
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?
    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 surveying the Monastery: (6)
    As of 2014-08-30 13:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (293 votes), past polls