Donations gladly accepted
If you're new here please read PerlMonks FAQ and Create a new user.
|
New Questions
|
Perl, Memcached and SASL
2 direct replies — 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;
|
RegEx Headaches
2 direct replies — Read more / Contribute
|
by oryx3
on Jun 19, 2013 at 13:39
|
|
|
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?
|
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);
print "@trans\n";
This works okay, but I wonder if there is a better and faster way.
|
HTML::Entities not working
1 direct reply — Read more / Contribute
|
by vasanthgk91
on Jun 19, 2013 at 02:56
|
|
|
I passing the data from html page(contactus.html) to cgi page.Every time I passing Other language string as input.Showing wrong length.
use HTML::Entities;
use CGI;
my $cgi=new CGI;
my $message=$cgi->param('message');
$message=decode_entities($message);
my $message_fld_length=length($message);
print "$message_fld_length";
The same code working... I passing the data from cgi page(contactus.cgi) to cgi page.I passing other language data as input.Here length working good.
Can u please give a suggestion.Why input coming from html page na not working decode_entites.
|
Permission & size are not visible
1 direct reply — Read more / Contribute
|
by gaurav
on Jun 19, 2013 at 02:54
|
|
|
Hi,I am very new to PERL.I have been confusing so far regarding directories.I mean,suppose if I run the below code
#!/usr/bin/perl
use warnings;
use strict;
opendir DH, "." or die "couldn't ope $!";
while ($_ = readdir(DH)) {
next if $_ eq "." or $_ eq ".." ;
print $_, " " x (30 - length($_));
print "d" if -d $_;
print "r" if -r _;
print "w" if -w _;
print "x" if -x _;
print "o" if -o _;
print "\t";
print -s _ if -r _ and -f _;
print "\n";
}
I am getting proper output as file-names ,permission and their sizes.
But whenever I had change "opendir" as
opendir DH, "/home/gaurav/Documents" or die "couldn't open: $!";
I have been getting only file-names,neither permissions nor file-size.
Any-one can help me regarding this.Thanks in Advance
|
Finding repeat sequences.
10 direct replies — Read more / Contribute
|
by BrowserUk
on Jun 18, 2013 at 14:55
|
|
|
Given a string of arbitrary (long) length that is known to comprise of a number of repetitions of an unknown length substring, (thought the last repetition my be incomplete), how to find that repeat sequence?
Eg. Given 'abcdabcdabcdabcdab' find 'abcd'.
Complications:
- The first (shortest) repetition may not constitute the full repetition.
Eg. In 'abcdabcdabceabcdabcdabceab'; 'abcd' is a false rep; the required rep is 'abcdabcdabce';
- As mentioned, the last part of the string may be an incomplete repetition.
The number of characters 'ignored' at the end of the string should be less than the length of the rep. Is is possible to code that into a regex? I guess it could just be checked afterwards.
I'm assuming that a regex solution would be possible, but I cannot wrap my brain around it today?
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|
References for ano subs fixed at compile time?
4 direct replies — Read more / Contribute
|
by LanX
on Jun 18, 2013 at 14:54
|
|
|
Hi
I'm pretty sure the answer is yes, but to be sure:
Are the references to anonymous code blocks in Perl always constant, because they are fixed at compile time?
DB<115> sub tst (&) { print "$_[0]\n" }
DB<116> tst {1,2,3,4} for 1..5
CODE(0xa396560)
CODE(0xa396560)
CODE(0xa396560)
CODE(0xa396560)
CODE(0xa396560)
Is it reliably so? I took a look at B::Concised opcode output and as far as could see it seemed so...
Please note that it is not the case for anonymous hashes
DB<118> sub tst (%) { print "$_[0]\n" }
DB<119> tst {1,2,3,4} for 1..5
HASH(0xa3963f0)
HASH(0xa396940)
HASH(0xa396720)
HASH(0xa3966c0)
HASH(0xa3963f0)
Cheers Rolf
( addicted to the Perl Programming Language)
|
Different answers for script and browser (LWP)
1 direct reply — Read more / Contribute
|
by Sly_G
on Jun 18, 2013 at 14:43
|
|
|
Site that I'm parsing with perl script recently moved to human-readable urls. I'm trying to get redirects from "id" requests to current addresses.
For example, when I'm going to "http://www.giftman.ru/show.php?id=294" in browser, site server redirects it to "http://www.giftman.ru/catalog/amulets/"
But when I'm trying to get this moved location in my script, I don't get 301 answer, it returns "200 OK" for some reason.
Script:
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
$ua = LWP::UserAgent->new;
$hh = HTTP::Headers->new(
User-Agent => 'Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101
+Firefox/21.0',
Accept => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*
+;q=0.8',
Accept-Language => 'en-us,en;q=0.7,ru;q=0.3',
Accept-Encoding => 'gzip, deflate',
Connection => 'keep-alive',
);
$ua->default_headers( $hh );
$cookie_jar = HTTP::Cookies->new( );
$ua->cookie_jar($cookie_jar);
@rename = (
294 ,
9806 ,
9807 ,
);
for $ren (@rename) {
$res = $ua->get("http://www.giftman.ru/show.php?id=$ren");
print $res->header('Location')."\n";
}
I used http sniffer to see what's going on with browser, and there's nothing special, really:
GET /show.php?id=294 HTTP/1.1
Host: www.giftman.ru
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firef
+ox/21.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.
+8
Accept-Language: en-us,en;q=0.7,ru;q=0.3
Accept-Encoding: gzip, deflate
Cookie: __utma=83753984.1287093182.1370328704.1371539232.1371576574.7;
+ __utmz=83753984.1370328704.1.1.utmcsr=(direct)|utmccn=(direct)|utmcm
+d=(none); __utmb=83753984.10.10.1371576574; _ym_visorc=w; PHPSESSID=4
+p0ql1mitskhkbg3os47v1hc11; __utmc=83753984
Connection: keep-alive
By accident I stumbled on this: if I use $ua->get("http://www.giftman.ru/show.php?id=$ren 0"), i.e. space and some symbols after URL string, I'm getting completely different response, and there it is, "301 moved" and new location.
I can't understand what's happening.
|
DBI placeholders and like statement
1 direct reply — Read more / Contribute
|
by jfroebe
on Jun 18, 2013 at 12:52
|
|
|
AFAIK, you can't use a placeholder with a SQL like statement. A coworker says you can. Can anyone confirm or deny it?
$query = 'select name from my_table where name like ?%';
my $sth = $dbh->prepare($query);
$sth->execute('Jo');
Basically he is convinced that you can. Nothing I've shown him has convinced him otherwise. Hopefully some prince or princess of the Perl Monks can break this stalemate
UPDATE:
poj pointed out that I was incorrect. The percent sign belongs in the execute() not the prepare query.
|
DBD::Sybase query execute hangs randomly for Sybase IQ 15.4
3 direct replies — Read more / Contribute
|
by cmahajan
on Jun 18, 2013 at 09:36
|
|
|
I am running DBI version 1.616 along with DBD::Sybase version 1.12 to connect to the Sybase IQ 15.4 server through one of my Perl modules. The platform is IBM AIX 5.3.0.0 maintenance level 5300-12
The problem that I am facing is that one of my simple queries randomly hangs for no apparant reason. The query is to select some data from the system view SYS.SYSTABLE. The code runs fine as such but every once in a while the code (execute statement) freezes and appears to be doing noting for a long time and I have to terminate the process forcibly.
Below is a fragment of code that I'm running (all variables are properly defined):
AutoCommit is set to 1
RaiseError is set to 1
$dsn = "dbi:Sybase:serverType=IQ:loginTimeout=240:server=$db_server_if
+c";
my $dbh = DBI->connect($dsn,
$self->get_db_username(),
$self->get_db_password(),
\%connect_options );
my $sqlA =<< "END_SQLA";
SELECT table_id
FROM sys.systable
WHERE table_name like '${uc_table_name}%'
AND length(table_name) = $table_name_len
AND user_name(creator) = '$uc_schema'
END_SQLA
my $sthA = $dbh->prepare($sqlA);
$sthA->execute();
Can someone help me figure out what might be wrong with the code or if any of the modules versions that I am using are incompatible with Sybase IQ 15.4.
Another interesting thing to note is that the same code works fine most of the times, but the problem occurs randomly at random times. I have checked the active connections in my database when the code hangs, there are no deadlocks or blocked processes. I can also see that the connection to DB is being established successfully but I do not see any active executing statements at all for the DB handle.
|
Using __DATA__ from a package
4 direct replies — Read more / Contribute
|
by yoda54
on Jun 17, 2013 at 22:19
|
|
|
package Test;
sub run {
while(<Test::DATA>)
{
print "$_\n";
}
}
__DATA__
1
#!/usr/bin/perl
use strict;
use warnings;
use Test;
Test::run();
|
|
|
New Cool Uses for Perl
|
Reducing crashers to a minimum program
No replies — Read more | Post response
|
by wumpus
on Jun 18, 2013 at 00:16
|
|
|
Inspired by the C-Reduce project, which reduces C programs that cause compiler crashes to a minimal program that still causes the crash, I have started perl-reduce, which does the same for perl programs which segfault, cause valgrind issues, etc. The first draft is at:
https://github.com/blekko/perl-reduce
and I'm hoping to collect some user experiences for a bit more tweaking before widely advertising it in the perl community. If you have a crasher that you've never narrowed down because it looked too tedious, please give perl-reduce a try.
|
RSS of Twitter search results after 11 June 2013
1 direct reply — Read more / Contribute
|
by ciderpunx
on Jun 17, 2013 at 10:41
|
|
|
Twitter recently got rid of the ability to get search results as an RSS as part of their API update of 11 June 2013.
I found those feeds rather useful, so I made a little screen scraper that reimplements the functionality without needing to auth against their API (it just pulls the results out of the web search page). I guess this will be good for a while longer, like enough time to switch to statusnet, identica, or whatever.
It might be of use to some others in the monastry and illustrates the power of HTML::TreeBuilder::XPath.
|
|
|
New Monk Discussion
|
[Community] Perl Mongers mailing list problems
3 direct replies — Read more / Contribute
|
by LanX
on Jun 19, 2013 at 11:37
|
|
|
Hi
I have experienced problems with some users of our local PerlMongers group whose mails were silently dropped.
One can't post anymore, the mails of the other one only reach me via a second account in the daily digest!?!
Do others experience similar problems with mailman?
If mailman becomes unreliable should I better consider switching to google groups or another public service?
Please gimme feedback...
Cheers Rolf
( addicted to the Perl Programming Language)
PS: Chose MonkDiscuss because it seemed appropriate for community problems.
|
|
|
|