Donations gladly accepted
If you're new here please read PerlMonks FAQ and Create a new user.
Want Mega XP? Prepare to have your hopes dashed, join in on the: poll ideas quest 2010 (Don't worry; you've got plenty of time.)
|
New Questions
|
doing tr/// on-the-fly?
on Mar 17, 2010 at 21:05
|
3 direct replies
|
by Anonymous Monk
|
|
|
I'm not getting it, and I have two questions.
- I'm wanting to do a transliteration on variable strings. I can do a tranliteration on hardcoded values:
#!/usr/bin/env perl
use strict;
my $s = 'eabcde';
$s =~ tr/abcd/efgh/;
print "$s\n";
Getting eefghe as a result. Fair enough.
I find in the archives that using variable strings requires eval. Yet when I try to implement this, I bomb out:
#!/usr/bin/env perl
use strict;
my $search = 'eabcde';
my $replace = 'efgh';
my $result = eval "tr/$search/$replace/";
print "$search\n";
print "$replace\n";
print "$result\n";
...gives the results:
eabcde
efgh
0
So how can I capture the result of the second tranliteration?
-
My second question lies in making these strings more complicated -- to the point of containing regular expression metacharacters. Obviously I need to escape them, but both search and replace strings are quite long and contain many characters which will require massaging.
Is there a default module which does such escaping, or is there a CPAN module which does what I need?
Thanks for any help you can provide.
|
[Offer your reply]
|
EPIC Debugger not stopping at breakpoint
on Mar 17, 2010 at 19:41
|
1 direct reply
|
by adambe
|
|
|
Hi all,
The Perl debugger in EPIC (Eclipse Perl Integration) is not stopping at a breakpoint that I set.
I tried checking / un-checking Window -> Preferences -> 'Suspend debugger at first statement'
but to no avail.
Has anyone got this working?
Thanks!
Adam.
P.S, I tried Padre but unfortunately the debugger didn't work at all
last time I checked.
Using Eclipse Classic 3.5.2 (Build id: M20100211-1343)
EPIC 0.6.35
Strawberry Perl v5.10.1
Windows XP SP3.
|
[Offer your reply]
|
Trouble with hashrefs
on Mar 17, 2010 at 18:48
|
2 direct replies
|
by aztlan667
|
|
|
OK, I've been beating my head against a very BASIC hashref problem. I'm trying to save the state of a hashref before and after a subroutine which might make assignments to the hashref. I've tried using Storable to either dclone or freeze/thaw the structure, but the subroutine continues to give me weird results. Here's an example:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Storable qw(dclone freeze thaw);
my $href = undef;
$href = { 'a' => { 'status' => 'OK' }};
print "BEFORE SUB: " . $href->{a}->{status} . "\n";
do_stuff($href);
print "AFTER SUB: " . $href->{a}->{status} . "\n";
sub do_stuff {
my $hash = shift;
my $hash2 = freeze($hash);
$hash->{'a'}->{'status'} = "NOT OK";
$hash = thaw($hash2);
print "IN SUB: " . $hash->{'a'}->{'status'} . "\n";
return 0;
}
This code returns the following:
$ ~/test.pl
BEFORE SUB: OK
IN SUB: OK
AFTER SUB: NOT OK
Am I missing something completely obvious? The value of $hash->{'a'}->{'status'} is getting overwritten to "NOT OK" in the sub, but then the entire hashref gets reassigned at the end of the sub, and the status is once again "OK". Once I'm out of the sub, the value returned is still "NOT OK". I don't get it. I'm completely familiar with the concepts of pass-by-reference (at least I thought I was). But if I'm completely reassigning the reference, shouldn't that be what the final value of the hashref is? I'm assuming the nested references also get overwritten, but I'm not sure. Any advice along the lines of "Hey, stupid, don't you know that...." would be greatly appreciated.
|
[Offer your reply]
|
Embedding perl script into C program
on Mar 17, 2010 at 17:53
|
1 direct reply
|
by darkdiver
|
|
|
Hello,
I would like to add a script into my C program (just embed it) and execute it through libperl. How can I do that? Simple eval has limitations on IO operations, etc. So it does not fit.
It's necessary to keep a script in the same binary (not in separate file).
I mean this:
const char script[] =
"Here is my big script with function 'exec_it()'";
static PerlInterpreter *my_perl;
my_perl = perl_alloc();
perl_construct(my_perl);
# here should be something to load the script into the interpreter. So this is the question...
perl_call_pv("exec_it", G_DISCARD);
|
[Offer your reply]
|
Seeking Comments & Feedback on Word/PDF project
on Mar 17, 2010 at 15:19
|
2 direct replies
|
by jedikaiti
|
|
|
So I have this project for work, and I am trying to decide which approach might be better. Any comments or feedback you can offer is much appreciated.
At work, there are some existing Perl scripts which dump a ton of data out of a database, add in some pre-written text, and compiles it into a handbook (850+ pages) in LaTeX and spits out a PDF. The goal here is to eliminate LaTeX from the process.
I had originally planned to make my modifications spit out a Word 2007 .docx file, which could then be easily modified as needed and saved to a PDF if desired. I've been playing around with the Template Toolkit module, and have confirmed that this is something I should be able to do without too many headaches. Also, the organization here has a standard Word template for engineering docs like this. I'm sure I could re-create it in a PDF, but I already have it in Word.
The other option is to remove the middleman and just go straight to PDF. To this end, I've been researching PDF modules on CPAN, and so far PDF::Create is looking like a good option. PDF::API2 was looking good (or at least powerful), but the lack of any real documentation is quite the turnoff. If I go this route, whatever PDF module I use needs to support bookmarks - in a document this big (850+ pages), there's a ton of them.
So my question to you, dear Monks: if this project were deposited on your desk, which path would you choose? What do you see as being the pros/cons of each? Anything else I haven't mentioned that you think I should not overlook?
Thanks a million!
Kaiti
|
[Offer your reply]
|
How do I put scrolling_list side by side in my start_form
on Mar 17, 2010 at 14:26
|
4 direct replies
|
by rakheek
|
|
|
Wise Monks,
I am still a newbie @ cgi. In my current project, I have 2 scrolling_lists and a radio_group in my cgi script. I would like to put the scrolling_lists side by side instead of one below another. Is there any way of doing this in cgi? Do I need to have templates?
Please help. So far the response from perlmonks is great.
Regards,
Rakhee
print $cgi->startform;
print $cgi->h3('Select Project to view QA Metrics');
print $cgi->br;
print $cgi->br;
print "<em><b>Enter Start Date [dd/mm/yyyy]</b></em><br>";
print $cgi->textfield(-name=>'start_date',
-default=>'07/03/2009',
-size=>9,
-maxlength=>80);
print $cgi->br;
print $cgi->br;
print "<em><b>Enter End Date [dd/mm/yyyy]</b></em><br>";
print $cgi->textfield(-name=>'end_date',
-default=>'08/01/2010',
-override=>true,
-size=>9,
-maxlength=>80);
print $cgi->br;
print $cgi->br;
print $cgi->br;
print "<b>Select Project to View QA Metrics</b><br>";
print $cgi->br;
print $cgi->scrolling_list(-name=>'Projects',
-value=>[
'ARES',
'POSEIDON_SW',
'DEIMOS',
'MIMAS',
'JUPITER',
'POSEIDON',
'DIONYSUS'],
-size=>8,
-multiple=>'true',
-default=>'ARES');
print $cgi->br;
print $cgi->br;
print "<b>Select from P1, P2, or P1+P2 Bugs Data</b><br>";
print $cgi->br;
print $cgi->radio_group(-name=>'P1P2_bugs',
-values=> ['P1', 'P2','P1-P2'],
-default=>['P1'],
-linebreak=>'true');
print $cgi->br;
print $cgi->submit(-value=>'Submit Project');
print $cgi->endform;
|
[Offer your reply]
|
How to manipulate SOAP::Lite Server answer to special format ?
on Mar 17, 2010 at 05:50
|
0 direct replies
|
by physi
|
|
|
Hello fellow monks,
I got a question about SOAP::Lite, which I can't fiddle out:
my $daemon = SOAP::Transport::HTTP::Daemon
-> new (LocalPort => 8088, Reuse => 1)
-> on_action(sub {})
-> dispatch_to('ServiceError');
print "Contact to SOAP server at ", $daemon->url, "\n";
$daemon->handle;
sub ServiceError {
print "ServiceError\n";
return SOAP::Data->name('ResponseType')->value('ACKNOWLEDGE');
}
This returns the following SOAP-XML to the client:
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc
+oding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s
+oapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://
+www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soa
+p/envelope/">
<soap:Body>
<ServiceErrorResponse xmlns="http://DataModel_v4.xxxxxxxxx.com">
<ResponseType xsi:type="xsd:string">ACKNOWLEDGE</ResponseType
+>
</ServiceErrorResponse>
</soap:Body>
</soap:Envelope>
but
this one I need to send to the client :
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc
+oding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s
+o
+apenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://w
+ww.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap
+/
+envelope/">
<soapenv:Body>
<ResponseType>ACKNOWLEDGE</ResponseType>
</soapenv:Body>
</soapenv:Envelope>
Is there a way to tell SOAP::Lite to suppress the <ServiceErrorResponse> Tags around my single-line message?
Thanks for any hints !
Cheers,
Christian
-----------------------------------
--the good, the bad and the physi--
-----------------------------------
|
[Offer your reply]
|
https request i got the cURL working
on Mar 16, 2010 at 23:07
|
1 direct reply
|
by elliottw
|
|
|
first off, this is my first post, i scanned through the faq did some searches, and now am here.
anyway, i'm trying to access this server with http requests and it's something i've never done before.
the curl looks like this:
curl https://secondroad.harvestapp.com/account/who_am_i -H 'Accept: application/xml' -H 'Content-Type: application/xml' -u elliott.williams@secondroad.com.au:******
and i get out this:
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<user>
<timezone>Sydney</timezone>
<admin type="boolean">true</admin>
<timestamp-timers type="boolean">false</timestamp-timers>
<email>elliott.williams@secondroad.com.au</email>
<id type="integer">111331</id>
</user>
</hash>
and that's perfect. i just can't figure out how to do it with a perl script. i'd like to do it without using any modules but LWP seems to be working.
thanks for the help. if i'm a complete idiot and there is a guide online for this, please direct me there, i've been messing around with this:
http://www.perl.com/pub/a/2002/08/20/perlandlwp.html?page=4
for a day with no luck.
cheers
|
[Offer your reply]
|
Sending HTTP credentials with SOAP
on Mar 16, 2010 at 21:37
|
3 direct replies
|
by astroboy
|
|
|
Hi
In have a class generated by SOAP::WSDL for a resource that requires Basic Authentication. The usual way to provide the credentials is to put something like this in your code
*SOAP::WSDL::Transport::HTTP::get_basic_credentials = sub {
return ($user, $password);
};
The underlying HTTP transport, LWP::UserAgent, won't supply the credentials until it receives either a HTTP::Status::RC_UNAUTHORIZED or a HTTP::Status::RC_PROXY_AUTHENTICATION_REQUIRED status code (401 or 407, I believe). This is correct, as specified in RFC2616.
Unfortunately, the SOAP service returns a 501 status, and a fault stating that the Basic Authentication credentials were never received. So I need a away around this. One way to to edit the class generated by SOAP::WSDL, and supply the credentials in the proxy = e.g. http://user:password@service. However, I really want to avoid this, as it will mean that I've hard-coded the authentication details in a package, which then isn't shareable by anyone else wishing to call the same service, and if I need to generate packages from the WSDL again, I''ll lose the credentials
So can anyone see a way around this?
|
[Offer your reply]
|
match a line and edit it
on Mar 16, 2010 at 21:01
|
2 direct replies
|
by Anonymous Monk
|
|
|
Hi,
I need to match a particular line from a file and delete it and add a newline for that matched line at the same line number. May I know how I can do this in perl? Can I do that with a single file handle?
Thanks,
Tom
|
[Offer your reply]
|
Hunt the func
on Mar 16, 2010 at 19:10
|
1 direct reply
|
by BrowserUk
|
|
|
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_64_BIT_I
+NT
USE_ITHREADS USE_LARGE_FILES USE_PERLIO
Built under MSWin32
Can anyone tell me what function is being called here:
## perlio.c(592) v5.10.1
return (*tab->Dup)(aTHX_ PerlIO_allocate(aTHX), f, param, fla
+gs);
And also, how did you track it down?
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.
|
[Offer your reply]
|
html output to div tag without submitting the form
on Mar 16, 2010 at 18:59
|
4 direct replies
|
by ksublondie
|
|
|
I'm using the Template module in a web app. I'm able to output an image inside a div tag without reloading the entire page using the following code in my html template:
<img src='user.pl?rm=getimage&image=docidF' height='350' width='750' align='center' border='1'>
which calls the subroutine:
sub getimage{
my $self = shift;
my $q = $self->query;
my $error='';
...
get the image and set $binData to the image data
...
print $q->header(-type=>'image/gif', -Content_Length=>length($
+binData)+1).$binData
}
which works like a charm. However, I'd like to now do the same thing, except instead of outputting an image, I want to output html without reloading the page. This html would contain the applicable select options based upon a previous answer. I don't want to submit the form and reload the page because honestly, there are too many other variables within the form and it would be a pain to reload.
I haven't been able to find anything remotely close to this yet. I'm assuming I'd use a simlar perl subroutine, but I'm not sure how I would call the subroutine in the html template. Is this possible?
|
[Offer your reply]
|
|
|
New Meditations
|
scripting frameworks - a cursory glance
on Mar 17, 2010 at 17:55
|
2 direct replies
|
by metaperl
|
|
|
I was looking to write a script that required quite a bit of
modularity and separation of generic concerns from the scripts
concerns. I have found 3 such frameworks (briefly discussed below) but
would be glad to hear of others
CLI::Framework
CLI::Framework seems to be the most useable of the 3. It has
good docs. It comes with two working samples, one simple example and
one much more complicated. The complicated example shows how to
maintain state in an application and share that state between
commands. One issue is that the object-oriented access to that state
in the command is via $self->$slot not
$self->app->$slot thus potentially creating conflicts
between application slots and command slots.
App::Cmd
App::Cmd is by the prolific and well known Ricardo
Signes. Like CLI::Framework, it support subcommands. It does not come
with complete samples. But the nice thing is you can find Ricardo on
irc.perl.org almost anytime of the day or night. Both App::Cmd and
CLI::Framework delegate option processing to
Getopt::Long::Descriptive.
One key difference between the two is that you manually map
application command names to modules in
CLI::Framework. App::Cmd automatically loads all
modules under the namespace of your application module.
Why is App::Cmd not quite as good as CLI::Framework
It's scary to pick someone over Ricardo, but the lack of working
examples, along with the lack of pre-packaged common commands make
CLI::Framework a bit more attractive.
App::Framework
App::Framework is interesting. The one thing it seems to lack
is any mechanism for commands. In other words, it aimed to make
applications more scaleable, but it has no support for application command
(and subcommand) dispatch. Both of the other frameworks have support
for subcommands, allowing for options to be specified both for the
application as well as the (sub)commands.
But only CLI::Framework provides fully working examples of it.
|
[Offer your reply]
|
Building a Development Environment on Ubuntu
on Mar 17, 2010 at 08:42
|
2 direct replies
|
by Xiong
|
|
|
Here is an environment for developing applications in Perl, suitable perhaps for the newcomer. It seems ironic that the rawest newcomer to the Perl Community needs a stable, independent development environment more than the grizzled guru; yet constructing that environment is not an entirely straightforward task (judging from the many blind alleys I have blundered into).
We all have different situations so let me begin by telling mine. If my shoes fit, you are more than welcome to try them on. This discussion may prove quite boring to the experts, of whom I beg pardon.
The Lesser Issues
When I first began to write Perl scripts, I didn't give much thought to it. A perl executable is installed by default with Ubuntu; any text editor will work; compiling and linking is not required. I was well underway before I realized that I'd made many poor choices. Here are better ones.
How can I manage all my files?
By this, I mean low-level management: starting, editing, and finding them.
How can I track changes to my code?
My old standby was always to copy my project folder, name the copy by number or by date, and move on. Then I discovered git. There are other tools for version control but I feel this is best for our needs -- and a world beyond just copying files.
How do I organize all my files?
This was the topic of my first post to PerlMonks and oddly, I still haven't got the definitive answer; better, I'm no longer worried about it. When you have dozens, eventually hundreds of files, no over-arching scheme is going to last. Be willing to create many folders and try to keep things together.
How do I get all this stuff?
All the tools I mention in this post (with the exception of perl itself) can be got through the Debian package manager, dpkg. There are several command line front ends, which I encourage you to look at; but the easiest way to install applications of any kind is probably to use the GUI Synaptic front end, found under System -> Administration -> Synaptic Package Manager. This will download and install for you most things that you will want on your Ubuntu system.
You do not want to use Synaptic to install perl itself!
Ubuntu comes with perl installed already; but you don't want to use that for your laboratory. (More on this later.)
How do I partition my hard drive?
Installing Ubuntu is beyond the scope of this post but there is one key point that any developer needs to take into consideration and that is partitioning.
Building a Development perl Executable
Since perl is indeed installed by default with every Ubuntu installation, it seems reasonable to use it to run your development scripts. This is not bad of itself but next, you will want to use some module you download from the excellent CPAN. This is a vast collection of useful (and sometimes not-so) stuff and you will want to taste it. That will also usually be okay ...
Congratulations! The new perl works. Now for the hard part.
Getting CPAN
There would be no point at all to any of this if I didn't want to be able to grab CPAN modules and install them into my development environment. This was not quite as easy as it might be.
Done?
Install some more modules. Write some scripts. Have Fun!
Vespers
Monks of much greater serenity than I may scoff not only at the extreme length of this post but also at the weasel words and general fudgery-doo.
First, I apologize to anyone who felt he had to read it all. I offer the defense that I would have loved dearly to have seen the whole gross tome six months ago. I've spent literally hundreds of hours studying up to get this far and no matter what I read, it contained only a small piece of the puzzle. Although I know much more now about building a development environment than I did, I would have been content to have it all handed to me and been free to concentrate entirely on learning Perl.
Second, my regrets to anyone offended due to the time spent explaining not-Perl stuff. I found that stuff essential to doing anything with Perl and it took me months to figure it out, a nybble at a time.
Third, my deepest sympathies to those who come looking for hints on how to develop on anything but Ubuntu, or for any other purpose. When I searched for web pages with practical advice (outside of the standard docs), I almost invariably stubmled on instructions for installing ActivePerl on a BeOS server through telnet. There don't seem to be many tutorials for my situation, since perl is installed by default and anyway, Ubuntu is Linux and any build here must be a snap.
Fourth, I'm more than willing to incorporate reasonable suggestions and sage corrections from anyone who considers to provide them. I'm only too aware of how little I understand what I just did and I'm convinced I only did so-so, perhaps less well considering the investment.
Finally, please take note that I owe far more than I can possibly repay to the many Saints and lights who made these tools available and those who condescended to explain them to me, sometimes five or six times. If oftoccasion these tools have made a poor cut, let us blame the hand that held them.
|
[Offer your reply]
|
RFC: A Perl module for DirectX
on Mar 16, 2010 at 21:17
|
3 direct replies
|
by kejohm
|
|
|
Greetings fellow monks,
I was hoping I could get some feedback on a module I am creating. It's a Perl interface to DirectX.
I have been working on it for a while now and so far it has been promising. I already have a fairly solid interface built for Direct3D, DirectInput, and DirectSound, although it still needs a lot of work.
So far, the interface is only a thin wrapper around the DirectX methods. In time, I hope to create an interface that is much simpler to use, especially for those who would like to use the module, but have little to no experience with DirectX.
I have been able to integrate it quite well with the Win32::GUI module. This makes the task of creating windows for a DirectX application quite simple.
I hope to eventually have support for as many DirectX components as I can, including older ones.
Any thoughts on the subject would be appreciated, especially from anyone out there who has experience using DirectX.
Thanks,
Kevin.
|
[Offer your reply]
|
Where ideas for oddball scripts come from...
on Mar 16, 2010 at 03:09
|
3 direct replies
|
by Lady_Aleena
|
|
|
Last night I evaluated random things on IRC (freenode), but that is probably not a surprise to most. Someone else came along and did it too for the numbers 1 through 4. I also like the Lingua::EN::Inflect module. So, I took the person's random 1-4 and wrapped it in NUMWORDS and ORD. When I ran it through buubot the first time, I didn't get any fourths. I thought then said that no one made it home, referring to baseball.
About a month ago, Leverage, one of my favorite television programs, was centered around baseball. That is probably where the whole baseball thing came from.
So, here is where the oddball script comes into play. I wrote a little script that will randomly generate half an inning. The odder thing is, I don't like sports, so writing a script for baseball is really out there.
I have been told that I should work with other people on a project. I have gone about as far as I want to with this script. If anyone wants to tweak what is currently there or expand it, go for it. I am not a fan of baseball, so I don't know all the rules. What I have below is extraordinarily simplistic. All I know is that it was fun to write, and as fun to watch the results.
This script is notable because it is the first script that I have written from scratch that includes recursion. All other work with recursion I have done is with the help of others. That I recursed this one without help is one reason that I am so happy with and wanted to share it.
So, where did the idea for an oddball script you wrote come from? :)
Have a nice day!
Lady Aleena
|
[Offer your reply]
|
|
|
New Cool Uses for Perl
|
Decode LaTeX flying accents
on Mar 15, 2010 at 11:16
|
2 direct replies
|
by ambrus
|
|
|
The following module tries to interpret names that have some characters replaced by LaTeX flying accent control sequences.
I need this to parse some bibliography entries, so I wrote this quick module. This does not claim to be a perfect solution, it won't work with all possible usages of all LaTeX packages out there, it only fixes the most common latin letters written in a not too strange way.
Usage. use Defly; and then call $s = defly($s) to fix a string. Input and output strings are utf-8 encoded (byte strings). This may output warnings for certain inputs that seem like they contain flying accents but that the module could not decode.
Example: perl -wMDefly -e 'print defly "Fran\\c{c}ois Vi\\`ete\n";' outputs François Viète (but utf-8 encoded).
For your own mental sanity, you may want to not read the implementation.
Update: the regex is so ugly because I want this to work in perl 5.8 too.
|
[Offer your reply]
|
|
|
New Monk Discussion
|
"Nodes To Consider" - Hide Nodes Already Voted (CSS)
on Mar 14, 2010 at 17:55
|
2 direct replies
|
by Perlbotics
|
|
|
Dear Monks,
I regularly visit the Nodes to consider (NTC) page and vote - which
sometimes involves a lot of scrolling and re-parsing.
The following few lines of CSS added to the On-Site CSS Markup text area
of the Display Settings nodelet helped me to get a somewhat clearer overview by
hiding the bodies of those nodes, I've already voted in the past.
In the hope, that some might find it useful too - here are the CSS alternatives
for completely or partially hiding NTC nodes already dealt with:
/* Nodes To Consider (id:28877):
Completely hide nodes that you have voted in the past.
*/
tr.ntc-body.ntc-voted, tr.ntc-head.ntc-voted { display: none }
/* Nodes To Consider (id:28877):
Hide bodies of voted nodes only.
Authorship, consideration information, and voting results still v
+isible.
*/
tr.ntc-body.ntc-voted ul { display: none }
Personally, I prefer the latter option (both checked with Opera and Firefox).
|
[Offer your reply]
|
|
|
|