Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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
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"?

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!

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.
Concise foreach expression
8 direct replies — Read more / Contribute
by ram31
on Aug 29, 2014 at 08:04
    Hi, Following ( snippet ) code works fine:
    foreach my $x (@names) { if ( $x =~ /test$/) { print "$path_name\n"; } }
    Instead of above one, i want to keep it simple as follows:

    print "$path_name\n" if ( $x =~ /test$/) foreach my $x (@names) # Not working

    print "$path_name\n" if ( /test$/) foreach (@names) # Not working.

    I appreciate your suggestions to optimize it.
Parsing through Hashes
2 direct replies — Read more / Contribute
by sidsinha
on Aug 29, 2014 at 05:22

    I have an hash of keys and values as below. Each key has multiple values, but each value could reference a key. For a given input key, I need to print the values, and if the value is also a key, then print the value of that key in brackets as below:

    Usb1 Usb2,Usb3 Usb2 val1,val2,Usb4 Usb3 val3 Usb4 val4

    Input : Usb1 print Usb2[val1,val2,Usb4[val4]],Usb3[val3] Input : Usb2 print val1,val2,Usb4[val4]

    The logic I tried is to first check if the input key exists in the hash then load the values of that key into an array Now, iterate through the array, print $_ , then compare if the value matches any key in the hash, if matches, print the value. But now, I dont get how long and how I can keep doing this, because the set of keys could reference another key and so on...


    Any suggestions or examples could help. Thankyou
WWW::Mechanize Webcrawler
1 direct reply — Read more / Contribute
by Thoery55
on Aug 29, 2014 at 02:43

    I'm currently new to using WWW::Mechanize and am using it to build a web scraping tool that will go onto a school website and pull course data so that the website I'm building can recognize conflicts. I currently have this code in Perl:

    #!/user/bin/perl use warnings; use strict; use WWW::Mechanize; my $browser = WWW::Mechanize->new; $browser->get( 'https://registrar.ucdavis.edu/courses/search/index.cfm +'); $browser->form_number(3); #Search Form $browser->select('subject', 'AAS'); $browser->submit(); print $browser->content();

    The way the website works, you go in, select a subject area, and then click "Search". Then a table populates based off what you selected in the forms above.

    I'm currently focused on just getting my script to select one option from the dropdown menu, click "Search" and then copy the results, but for one, I'm not sure if it's actually working (It's not giving me any errors, but I'm not sure it's doing anything) and two, I'm not sure how to view the data that pops up in the table. Any help would be appreciated!

Sending Email with Dancer::Plugin::Email
No replies — Read more | Post response
by tushardave26
on Aug 28, 2014 at 23:04

    Hello Folks,

    Currently, I am developing Dancer web application. As part of my application, I would like to send email to users. I am referring Dancer::plugin::Email manual to accomplish the task. I adapted the code form the manual. But some how my code is neither working nor producing any error. Below find my code:

    use Dancer ':syntax'; use Dancer::Plugin::Email; use Try::Tiny; post '/ednContacts' => sub { try { email { from => params->{'email'}, to => 'tdave@example.edu', subject => 'Contacting for EDN Web site', body => params->{'message'} }; } catch { error "Could not send email: $_"; }; };

    FYI, I am using MAC OSX 10.9.4. And running my application on localhost:3000

    Can some one point out any problem in my code?

    Thanks.

Default named params with an embedded hash
2 direct replies — 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.

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

    The best computer themed movie is:











    Results (291 votes), past polls