Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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
intersection of scalar with 1D array and 2D array Matlab=>Perl
1 direct reply — 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
1 direct reply — 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.....
Install issue with selenium
No replies — Read more | Post response
by pdxperl
on Aug 29, 2014 at 09:33
    I'm on Windows 7, Strawbeery Perl version 5.18. I'm installing Test::WWW::Selenium and getting this error:
    t/test_default_server.t .. # Test::WWW::Selenium running open (file:// +C:\strawbe rry\cpan\build\Test-WWW-Selenium-1.36-ZkGVDi\t\files\test_click_page1. +html) # Error requesting http://localhost:4444/selenium-server/driver/: # ERROR: Command execution failure. Please search the user group at ht +tps://grou ps.google.com/forum/#!forum/selenium-users for error details from the +log window . The error message is: Access to 'file:///C:/strawberry/cpan/build/T +est-WWW-Se lenium-1.36-ZkGVDi/t/files/test_click_page1.html' from script denied # Failed test 'open, file://C:\strawberry\cpan\build\Test-WWW-Seleni +um-1.36-Zk GVDi\t\files\test_click_page1.html' t/test_default_server.t .. 1/7 # at t/test_default_server.t line 43. # Test::WWW::Selenium running get_text (link (?^:Click here for next p +age) link contains expected text) Error requesting http://localhost:4444/selenium-server/driver/: ERROR: Element link not found
    This appears to be a known install issue http://www.cpantesters.org/cpan/report/70509994-e7d1-11e2-be3b-b82b1f19502a I've run as administrator, doesn't make a difference. The file exists, and permissions are open for authenticated users. So if you're using Selenium, are you just doing a force install and ignoring failures, or is there a workaround? I did a force install, and am able to run some basic scripts, but I'm getting some odd errors that made me wonder if there was a real install/driver issue that was being flagged in the install testing.

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 chilling in the Monastery: (9)
    As of 2014-08-30 08:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (291 votes), past polls