Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
Parsing Motorola S-Rec file
3 direct replies — Read more / Contribute
by gri6507
on Sep 02, 2014 at 17:14
    Fellow monks,

    I was rather surprised that my CPAN search for a module to parse Motorola S-record files (see Wikipedia for details) returned no useful results. Also, my Google search for this utility returned only one useful result (some Renesas PDF with poorly written Perl code). Surely I can't be the only one who needs to convert S-rec files into other formats. I can, of course, write my own, but I didn't want to reinvent the proverbial wheel. Does anyone have any references?

Point me in the right direction with OO inheritance and static variables
6 direct replies — Read more / Contribute
by Amblikai
on Sep 02, 2014 at 05:54

    Hi Monks, still getting to grips with OO Perl. I know there are modules out there like Moose et al, but i' writing classic perl Objects as a learning experience.

    I'm not sure where to begin with inheritance though. I was hoping someone could point me in the right direction?

    I'd like to have a class which has some static attributes. For example if i create an object it will be created with hardcoded attributes without me passing them as arguments to the "new" constructor. How do i go about that?

    Then i have a second class which i will be creating objects which can only have attributes which are found in the previous class. I don't know how to get the second class to know it can only have those attributes and to only allow the object to be called with those attributes having variables assigned to them.

    Any help greatly appreciated.

Combining 2 variable?
6 direct replies — Read more / Contribute
by Krillian
on Aug 31, 2014 at 08:06

    Hi all, Not sure exactly what this is called so cannot find a tutorial. Here is the code:

    $a3 = "Hello"; $b = "a"; $c = "3"; $d = "${$b.$c}"; print $d; # $d should be prints as Hello

    This works fine, but if I change it a little:

    $a[3] = "Hello"; $b = "a"; $c = "[3]"; $d = "${$b.$c}"; print $d; # $d should be prints as Hello

    It no longer works... What am I doing wrong?
    Any help would be very much appreciated and thank you very much in advance!

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 = ""; 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\"); $smtp->datasend("To: account\\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


    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!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 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( ' +'); $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 => '', 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?


Default named params with an embedded hash
2 direct replies — Read more / Contribute
by neilwatson
on Aug 28, 2014 at 15:12


    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

New Cool Uses for Perl
Commodore disk image processor thingy
3 direct replies — Read more / Contribute
by rje
on Sep 01, 2014 at 19:57
    Dear Perlmonks,

    I wrote a Perl library, and I think it's pretty cool, but I'm also asking your opinions about it - is it worth putting on CPAN, for instance.

    It is a pure-Perl library for handing Commodore disk images. For those needing a refresher, these are digital images of diskettes and hard disks used by Commodore computers in the late 1970s thru the 1980s.

    It's hosted inside my network, behind my modem's firewall, by my Raspberry Pi running a cheapo web server I wrote (also in Perl) specifically for the purpose of serving and manipulating Commodore disk images.

    My library handles D64, D71, D81, D67, D80, D82, and X64 image types. Each format is a little package (about 8k) with data specific to that image. I made them packages, although I could have just used parametric data. These packages are essentially parametric data anyhow, and provide context to a generic engine that knows how Commodore disk images work.

    The library is 140k (includes good POD documentation, which is rare for me) split among about 20 files.

    First, is it worth posting to CPAN. It's awfully specialized. Maybe it would be better just to post it as a tarball on a website (or github?).

    Second, it's been nearly 10 years since I've uploaded to CPAN, and I am intimidated by the process. Yes, I've read the rules, but I'm concerned about uploading 20 related files in one batch. Anyone have any advice beyond what PAUSE has to say?

    Thanks for listening.

LED blinking Morse code from Raspberry Pi
2 direct replies — Read more / Contribute
by rje
on Aug 30, 2014 at 11:23
    With the handy Device::BCM2835 package, I tossed together this little package so I could send "morse code" out on an LED I connected to GPIO Pins #5 and #7.

    (FYI: the Raspberry Pi can run a number of Linux systems, all with Perl. I wrote a tiny HTTP server on it which lets me create and serve Commodore disk images, also allowing me to extract and inject files, in Perl of course. It runs behind my firewall...)

New Monk Discussion
PerlMonks meets Twitter Bootstrap
1 direct reply — Read more / Contribute
by tobyink
on Sep 02, 2014 at 15:56

    Here's what it looks like: screenshot.

    And, here's how to do it. Paste the following into your Free Nodelet:

    <script type="text/javascript" src="// +n.js"></script> <script type="text/javascript" src="// +p/3.2.0/js/bootstrap.min.js"></script> <script type="text/javascript" src="// +ighlight.js/8.2/highlight.min.js"></script> <script type="text/javascript" src="//"> +</script>

    Then in Nodelet Settings make sure your Free Nodelet isn't hidden.

    If you want to play around with the idea, adjust the URL to point to a script file on your own server; grab a copy of the Javascript and CSS files and have fun!

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 imbibing at the Monastery: (10)
As of 2014-09-03 02:59 GMT
Find Nodes?
    Voting Booth?

    My favorite cookbook is:

    Results (35 votes), past polls