Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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
DES ECB mode using DES_PP
1 direct reply — Read more / Contribute
by v4169sgr
on Aug 29, 2014 at 04:21

    I use Perl 5.10 ActivePerl 5.14 on win7. I am a humble user, and don't really understand what I am doing.

    I have a requirement to connect to a remote host and send locally encrypted messages, using DES ECB mode encryption. This is not my choice, but a part of the requirement. I am trying to find out how to implement DES ECB mode encryption simply in Perl.

    I do not have access to a C compiler, and cannot be the local administrator on my machine. I don't have download rights either, but can copy / paste source from CPAN into .pm files in my C:. I have copied the source for and to C:\Perl 5.10\lib\Crypt\ from CPAN. I've chosen as my understanding is that I don't need a C compiler to use it.

    I need to make sure that I am using the ECB hex encryption function correctly. My code currently looks like this:

    use Crypt::ECB qw(encrypt decrypt encrypt_hex decrypt_hex); my $ascii_key = "0123456789abcdef"; my $plain_text = "Now is the time for all "; print encrypt_hex($ascii_key,"DES_PP",$plain_text,"0");

    This 'works' in that it runs without errors, but produces output:


    From the example I am using in the original DES ECB mode specification (FIPS 81), I should see:


    What am I doing wrong?

    Thanks in advance for all responses. Yes, I know there are much better ways of achieving encrypted traffic, and I know too that I should really do things the proper way via full local installation and C compilers etc, but I can't do any of that because of local policies, and still need to solve the problem.

WWW::Mechanize Webcrawler
No replies — Read more | Post response
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!

A TableMatrix row selection question
2 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 28, 2014 at 23:20
    Hello PerlMonks,

    This is a TableMatrix row selection question. I noticed that there is a four year old thread on this However I later felt that it is better to post it as a new question

    1. Where do I find what are all the fields that a Perl/Tk programmer can access from an XEvent object and what do those fields stand for? (Mastering Perl/Tk book by Oreilly Press doesn't give any details except Chapter 15 merely makes a mention of it when accessing 'K' and 'N' for keysym text and decimal). I also looked at which has following line
    sub XEvent { shift->{'_XEvent_'} }
    but I'm unable to go any further than this to understand the same.

    2. In the selectionSet and selectionIncludes methods the above specified thread used the values: '@' . $Ev->x . "," . $Ev->y what does this @ and the full expression stand for. I could not find anything in the perldocs for TableMatrix (and other widgets like TList decendants which also have these methods).

    As I'm still trying to learn Perl and Perl/Tk I had to spend few hours trying to look around but to no avail. Therefore any information would be very useful. Many Thanks
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?


Search a SQL Table and Delete Records
1 direct reply — Read more / Contribute
by Katanya
on Aug 28, 2014 at 19:52

    Is there a way to use perl to search through a designated SQL table, looking for keywords, and delete any records found with those keywords? I would like to deploy this on my website as a scraper, to go through comments after they have been made in order to remove spam. I guess that adds the necessity of the keyword search needing to be done in a specific field in the table.

Safe Execute System Command and Capture Output
1 direct reply — Read more / Contribute
by jeffm712
on Aug 28, 2014 at 18:50

    The jist is I want to execute a system command without worrying about shell metacharacters or quoting, and I'd also like to capture both STDOUT and STDERR.

    system PROGRAM LIST is an obvious place to start. This seems to avoid the shell like I wanted, but I can't capture the output. To do that, the docs suggest I use backticks. Backticks let me get the output, but now I have to worry about shell metacharacters again. Using open also seems to rely on the shell.

    So... is there a shell escape function I can use? Or is there a module to safely handle spawning and communicating with processes? Or some other standard practice? What's the way to do this?

ZFS module
1 direct reply — Read more / Contribute
by faber
on Aug 28, 2014 at 15:36
    Hi Folks, I'm writing some basic monitoring tools in perl for my local ZFS file systems. I'm considering calling the module ZFS::Tools or Filesystem::ZFS or possibly Sys::Filesystem::ZFS though the current Sys::Filesystem doesn't appear to have the correct framework for many of the features of ZFS. Other suggestions are welcome. Thanks!
Default named params with an embedded hash
1 direct reply — 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

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 = ' +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/

How to pass Windows filepaths on command line
5 direct replies — Read more / Contribute
by bangor
on Aug 28, 2014 at 13:46
    I'm useless at Windows and failing at passing in a file path to a script from the command line:
    perl --file='test.txt' ... Could not open 'test.txt': No such file or directory at
    Note the quotes around test.txt. I tried with the full path
    perl --file='C:\scripts\test.txt' ... Could not open 'C:\scripts\test.txt': Invalid argument at
    Script and file are in the same directory. Any help appreciated

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 wandering the Monastery: (9)
    As of 2014-08-29 09:08 GMT
    Find Nodes?
      Voting Booth?

      The best computer themed movie is:

      Results (277 votes), past polls