Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Your skill will accomplish
what the force of many cannot
 
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
Terminal Form data entry
2 direct replies — Read more / Contribute
by pgduke65
on Jun 19, 2013 at 19:13
    Hi Monks,

    I have a desire to create a script that would essentially present the user with an input form that they can fill out with values that would be used elsewhere in the process.

    I could do so by prompting and getting input. Then prompt for the next value, etc. but this does not provide the user experience I hope to provide.

    I have seen examples of using a web form. However, in this case, we are unable to install/use a web server. Is there a way to do data entry into a form on a terminal window?

    Thank you.
How do I remove spaces between sequences in a file
3 direct replies — Read more / Contribute
by bingalee
on Jun 19, 2013 at 17:53

    I thought this would be an easy task.Basically I have a file with sequences separated by white spaces and new lines.

    Like this

    GAGGGTGCAATCTACAAGAGTGCGGGTTCGCGTTCAGTCCAAGCTGAACATAAACGCAAC GCAAGGCCCCTCGACGCAGATACCGCGCTCAGGAGCATTCGAGAAGCCGAAGAAAATTCG AAGACGAGGACCAGCTACACTGCGGACGGACTTCGGGCATGGAGGGCCAGTTCCAG GTTGGCAAGGAGGAGGTCATCCAAGCATGGTACATGGACGACAGTGAAGAGGACCAGAGG CTTCCTCATCATCGTGAGCCCAAAGAATTCATTCCTCTCGACAAACTTTCCG AACTAGGAATATTAAGCTGGCGCCTAAATGCTGATGATTGGGAGAATGATGAGAACCTCA AGAAAATTCGTGAAGCCAGGGGTTACTCTTACATG GACATTTGTGATGTGTGCCCAGAGAAGTTGCCAAATTACGAGGCTAAGATAAAGAATTTC TTTGAAGAACACTTGCATACTGATGAAGAGATACGATATTGCCTTGAGGGTAGCG GCTACTTTGATGTGAGGGACCAAGATGATCAGTGGATCCGTGTAGCGGTAAAGAAAGGGG GCATGATCGTTTTGCCTGCAGGAATGTATCATCGCTTTACGTTGGATAGTGACAACTACA TCAAG GCAATGCGTCTATTTGTGGGTGAGCCTGTCTGGACACCATACAATCGTCCGCATGACCAT CTCCCGGCTAG

    when I used split and then joined it I got the entire sequence in one line..I dont want that.

    The same thing happened when I did this

    foreach $value (values(%seq)) { $value=~s/\n|\t|\r//g; }

    Any idea how I can format my sequence file?

tail pipe
2 direct replies — Read more / Contribute
by aquercus
on Jun 19, 2013 at 17:42

    A good answer to the question can be found at (http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/Tail.pm).

    The environment is ActiveState perl on a windows 7 box. I want to read records into my perl program from a file as they are being written to it by an external program. While windows does not have an internal tail command, MS does provide one as described at this site: ( http://www.windows-commandline.com/2010/08/tail-command-for-windows.html). Upon execution, this works fine except the output from tail goes to a command window and is not capture-able in perl by any means I can develop. I'm seeking an equivalent capability using perl's file IO functions. Thanks;

    #! /usr/bin/perl my $cmdtorun = "tail -f D:/prjct/logger/2013-06-05.dlg |"; open(TL, $cmdtorun) || die "Failed: $!\n"; while ( <TL> ) { print "Got: $_\n"; }
Perl, Memcached and SASL
1 direct reply — Read more / Contribute
by moritz
on Jun 19, 2013 at 16:03

    I need to talk to a memcached server in Perl program, and I need to uses SASL.

    Now Perl has a whole bunch of memcached client libraries, but seems that none supports SASL.

    The closest seems to be Memcached::libmemcached, which is a very thin wrapper around the C libmemcached library. In theory, all I need to do is to expose the memcached_set_sasl_auth_data function, call it once, and be happy. In practice, this segfaults (I've tried this in the sasl branch of this repository). It seems that the libmemcached library bundled with the perl module is very out of date, and upgrading to a new one is no easy task, because much of structure of the header files changed.

    My next hope was that it could be relatively easy to pair up Authen::SASL and one of the existing memcached clients. However Memcached only supports SASL for the binary protocol, and all the other perl modules only support the text protocol (please correct me if I'm wrong here).

    Finally there's a small pure-perl client in the tests of the memcached server, which seems to be my only remaining option. I'm reluctant to use it though, because it's not maintained as a "real" client, has no docs and no proper error handling.

    So, my question is: Are there any options I overlooked? Or is somebody maybe even working on a client with sasl support? (Or is there another comparable open-source distributed memory cache with perl libraries that support authentication?).

Overloadding array_each when Unit testing with Test::Deep
No replies — Read more | Post response
by willjones
on Jun 19, 2013 at 15:46

    Alright, I've spent way too long trying to figure out a way to make this work like I want. Perhaps the perlmonks can help me. :)

    I basically want what array_each does only I want it to support a hash OR an array. If it gets a hash it should just do a standard hash to hash comparison, if it gets an array it should do what array_each normally does.

    I at first tried to make my own sub called array_each_orHash that took a comparator value. Here's the code I wrote...

    sub array_each_orHash { my $comparator = shift; my $handleArrayOrHash = sub { my $data = shift; return array_each($comparator) if (ref($data) eq "ARRAY"); return $comparator if (ref($data) eq "HASH"); }; return code( \&$handleArrayOrHash ); }

    This was mysteriously always resulting in a passed test, until I realized the mystery. I wasn't supposed to return an object when using the "code( ... )" sub I was supposed to return 0 or 1, or an array with 0 and the reason it failed. Okay, so then I modified it a bit...

    sub array_each_orHash { my $comparator = shift; my $handleArrayOrHash = sub { my $data = shift; my $result = (0, 'must pass an ARRAY or HASH'); $result = eq_deeply($data, array_each($comparator)) if (ref($data) +eq "ARRAY"); $result = eq_deeply($data, $comparator) if (ref($data) eq "HASH"); return $result; }; return code( \&$handleArrayOrHash ); }

    This actually works except I get no useful debugging diagnostic info except that the test failed. And the diagnostic I do get tells me a CODE block was run. I don't really want that to be displayed. The "code" was really just a means to an end so I could try to overload array_each.

    I thought about making my own cmp_deeply sub that actually just checks for array_each with a non-array and if found calls the real cmp_deeply without the array_each. If not found then it could call the real cmp_deeply with the array value and array_each. But the problem with this approach is in handling cases where the array_each is embedded deeply within a value's structure. Do I write my own recursive deep diving routine to search for array_each (Test::Deep::ArrayEach) class instances and look for what they are comparing against somehow? No way!

    Ok, so what is the correct way to do this? It seems like simply making my own version of Test::Deep::ArrayEach is really the best solution here. Adding something like Test::Deep::ArrayEachOrHash. But I don't know how to make my own ArrayEach like this and haven't found useful information on how to do something like that. I did find the following code here: http://searchcode.com/codesearch/view/16731024 (Shown below)

    But, how do I make my own "array_each_orHash" keyword and connected it to some code in package Test::Deep::ArrayEachOrHash? Am I grossly over-complicating things here or going the wrong direction with this? Any help would be appreciated. Thanks...

    use strict; use warnings; package Test::Deep::ArrayEach; use Test::Deep::Cmp; sub init { my $self = shift; my $val = shift; $self->{val} = $val; } sub descend { my $self = shift; my $got = shift; my $exp = [ ($self->{val}) x @$got ]; return Test::Deep::descend($got, $exp); } 1;
Using PAR pp to make an executable with necessary dll files
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jun 19, 2013 at 14:13
    I created an executable from a perl script that works fine, but it requires that a few dll files are in the same directory. It's not a huge deal to just put everything into a zip archive, but I would prefer that everything was in one standalone executable.
RegEx Headaches
2 direct replies — Read more / Contribute
by oryx3
on Jun 19, 2013 at 13:39

    Here's what I've got:

    DB<30> x $_ 0 'ActionLogs.1.1998.xml' DB<31> x /(\d+\.)+.*xml/g 0 1998. DB<32> x /(\d+)+.*xml/g 0 1

    Here's what I want:

    0 1 1 1998

    How do I get from what I've got to what I want?

Web Services
2 direct replies — Read more / Contribute
by packetstormer
on Jun 19, 2013 at 12:03

    Hello Monks

    This question, like a lot of my questions, if more looking for suggestions that actual code problems.
    I have been thinking about creating a small, simple web services script and any place I look for information/tutorial seems to suggest it as being quite difficult. I have a really simple and crude script below and I am looking for thoughts on why this type of approach is bad!
    It is a simple process and the setup to return a JSON string.

    Ideally I would create a backend DB with the auth details (for valid user API keys) and expand on the query/queries to return more attributes. My main concern is the method. Is this a really bad way to provide a web services service!? (Sitting on a standard Apache2 instance at the moment)

    #!/usr/bin/perl use strict; use warnings; use DBI; use CGI; use JSON::XS; # Naively simple web service!? my $cgi = new CGI; my $auth_code = "XD9920399fldkkxzmfoJfkYYUS2"; my $lookup = $cgi->param("lookup"); my $client_key = $cgi->param("client_key"); my $print; # Expand this later to return unique error for each possible omission if ( (! defined $lookup) || (! defined $client_key) || ($client_key ne + $auth_code) ) { $print = encode_json {error => 'You must provide a lookup and vali +d client key'} } else{ my $dbh = new_dbh(); my $sth = $dbh->prepare("SELECT title,next_episode FROM watcher WHERE userid = ?"); $sth->execute($lookup); $print = encode_json $sth->fetchrow_hashref(); } print "Content-type: text/html\n\n"; # Send back the Json string print "$print"; sub new_dbh { my $db_driver = "mysql"; my $db_name = "shows"; my $db_host = "localhost"; my $db_port = "3306"; my $db_user = "root"; my $db_passwd = "xxxxxx"; my $dbh= DBI->connect("DBI:$db_driver:dbname=$db_name;host=$db_hos +t;port=$db_port", $db_user, $db_passwd,{RaiseError => 1, mysql_enable_utf8 => 1, }); $dbh->{TraceLevel} = 2; # disable when live return $dbh; }
user input file
3 direct replies — Read more / Contribute
by torres09
on Jun 19, 2013 at 09:25
    hey

    I have a small issue that I have written a code where I have predefined my file , but now I want that the file should be entered by the user . So this is my code

    my $file="Working_On.csv"; open(FILE,"<","$file"); my @lines=<FILE>;

    so what I am doing is converting that csv file to an array . please tell me a way so that Working_On.csv should be entered by the user

Transform Sequence Problem
4 direct replies — Read more / Contribute
by wbirkett
on Jun 19, 2013 at 07:45

    I need an efficient way to process a sequence of transforms. For example, here are some individual transforms as code references:

    # some code references $f1 = sub {map {$_ + 1} @_}; $f2 = sub {map {log($_)} @_}; $f3 = sub {map {$_ * 3} @_};

    They may be combined into a sequence

    # combined transform sub trans1 {&$f3(&$f2(&$f1))}; # some data @data = (1, 2, 3); # call the transform @trans = trans1(@data); print "@trans\n";

    The sequence could have fewer or more steps, so I would like to make an array of code references:

    # make a sequence array @seq = ($f1, $f2, $f3); # combined transform sub trans2 { # for each code reference for (@seq) { # transform data @_ = &$_; } # return return(@_); } # call the transform @trans = trans2(@data);

    This works okay, but I wonder if there is a better and faster way.


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 studying the Monastery: (12)
    As of 2013-06-20 01:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How many continents have you visited?









      Results (677 votes), past polls