Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
good chemistry is complicated,
and a little bit messy-LW
 
PerlMonks

The Monastery Gates

 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | Snippets | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Code | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

( #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.

Want Mega XP? Prepare to have your hopes dashed, join in on the: poll ideas quest 2007  (10283 days remain)

New Questions
GD + layering text over existing image
on Nov 22, 2008 at 08:12
3 direct replies by ultranerds
    Hi,

    I'm trying to write a script that will:

    1: Grab an image (a pre-defined one)
    2) Overlay some text (the date) over this image.

    I've had a google around, and can't find anything (unless I'm not searching for the correct queries =))

    Could anyone provide me with some example code? At the moment, I've got the basics - but need to have an image showing towards the back of the image:

    #!/usr/local/bin/perl
    
        use CGI::Carp qw(fatalsToBrowser);
        print qq|Content-type: image/png \n\n|;
    
        use GD;
    
        # create a new image
        my $im = new GD::Image(100,100);
    
        # allocate some colors
        my $white = $im->colorAllocate(255,255,255);
        my $black = $im->colorAllocate(0,0,0);       
        my $red = $im->colorAllocate(255,0,0);      
        my $blue = $im->colorAllocate(0,0,255);
    
        # make the background transparent and interlaced
        $im->transparent($white);
        $im->interlaced('true');
    
        # Put a black frame around the picture
        $im->rectangle(0,0,99,99,$black);
    
        # Draw a blue oval
        $im->arc(50,50,95,75,0,360,$blue);
    
        # And fill it with red
        $im->fill(50,50,$red);
    
    #   my $courier = GD::Font->load('/home/trust/etrust.pro/cgi-bin/trust
    +/LiberationSerif-Bold.ttf') or die "Can't load font";
        $im->string(gdSmallFont,5,10,"Testing",$black);
    
        # make sure we are writing to a binary stream
        binmode STDOUT;
    
        # Convert the image to PNG and print it on standard output
        print $im->png;  
    

    TIA

    Andy

[Offer your reply]
Analyzing opcodes of lvalue-subs...
on Nov 20, 2008 at 20:26
3 direct replies by LanX
    Hi

    I'm trying to understand lvalue subs on the opcode level and would appreciate some help. For the motivation please read Another approach to extend lvalues ?

    here the perlcode I want to analyze

    my $scalar;
    test();
    
    sub normal :lvalue {
        proxy();
    }
    sub proxy :lvalue  {
        $scalar;
    }
    
    sub nlv {
        my $x="not lvalue"
    }
    
    sub test {
        nlv();
        normal=42;
        print $scalar;
    }
    
    and now how the corresponding opcode looks like, I added the original code as comment. *

    Well I'm still struggling to understand the opcodes, but please look at the lines 6-a and k.

    my interpretation is that by assigning a value to a lvalue-sub the steps are:

    1. cache the value
    2. call the lvalue-sub, which returns a var by refrence
    3. assign the cached value to this var

    so even on the level of the opcodes the lvaluesub has no chance to know which value will be assigned to the variable he returns ... Correct?

    I'm a little bit confused about line j, what means "rv2cv" (it's the first time this happens right before a sub call)?

    I googled through perlguts op.c and concise.pod but can't get a sufficient answer...

    Thanx Rolf

    * I know with 5.10 I wouldn't need to do it manually but I'm sticking on 5.8.8. I have to figure out how to safely install two different perl-versions on the same system, so that I can maintain both with aptitude.


[Offer your reply]
Fast, Efficient Union and Intersection on arrays
on Nov 20, 2008 at 11:31
7 direct replies by barvin
    Hi all,

    I'm doing graph traversal and calculating the Jaccard distance on each pair of vertices. Calculating intersection and union are consuming 98% of my processing time.

    I've tried Set::IntSpan, Set::Array and List::Compare, but they are all even slower than my own code. Is there a VERY fast (maybe implemented in C) way to calculate intersection and union on two arrays? Just for interest, my implementation is ($in and $jn are array refs of positive integers):

    sub get_int_uni {
    
            my ($in, $jn) = @_;
            
            my (%int, %uni);
            for my $i (@$in) {
                    $uni{$i}++;
            }
            for my $j (@$jn) {
                    $int{$j}++ if $uni{$j};
                    $uni{$j}++;
            }
            return ((scalar keys %int), (scalar keys %uni));
    }
    

[Offer your reply]
Log4Perl to send mail via SMTP
on Nov 20, 2008 at 08:08
2 direct replies by weismat
    Maybe I am missing something obvious, but how do I send SMTP mail via Log4Perl?
    I use this configuration

    log4perl.category = FATAL, Mailer
    log4perl.appender.Mailer = Log::Dispatch::Email::MailSend
    log4perl.appender.Mailer.to = x@z.com
    log4perl.appender.Mailer.from = y@z.com
    log4perl.appender.Mailer.subject = Something's broken!
    log4perl.appender.Mailer.layout = SimpleLayout
    log4perl.appender.Mailer.Server = x.x.x.x
    log4perl.appender.Mailer.smtp = 1

    I have tested that Mail::Mailer works, but I do not get it to work with the standard appender. The constructor for Mailer needs to be in the following format: $mailer = Mail::Mailer->new('smtp', Server => $server);

[Offer your reply]
Tkx: "invalid command error" OS X
on Nov 19, 2008 at 15:33
2 direct replies by vlsimpson

    I am in the process of moving a Perl/Tk text editor to Perl/Tkx.

    The following code works fine on Windows XP ActivePerl 5.8/5.10 but my OS X testers are getting this error:

    invalid command name "tk::text" at tkx-test-1.pl line 24. (There's a FIXME: on the offending line.)

    I've searched on this but no results that seemed applicable.

    Thanks for any and all responses.

    use warnings;
    use strict;
    
    use Tkx;
    
    my $VERSION = "1.0.0";
    my ($mw, $tw);
    $mw = Tkx::widget->new(".");
    
    $tw = $mw->new_tk__text( # FIXME: Barfs on OS X
        -width => 40, 
        -height => 10 );
    
    $tw->g_grid;
    $tw->g_focus;
    
    $tw->insert("1.0", "If you can read this it worked.");
    
    Tkx::MainLoop();
    exit;
    


[Offer your reply]
windows vs unix: different behaviour with exec()
on Nov 19, 2008 at 14:56
3 direct replies by abecher
    I need to know if there is a solution to exec() acting differently on windows vs unix. Best way to see the difference is using 3 little perl scripts (I'm displaying them from unix with the "more" command, but they will run as-is on windows also)
    -> more testexec*
    ::::::::::::::
    testexec.pl
    ::::::::::::::
    #!/usr/bin/perl
    system("testexec2.pl");
    print "Done $0\n";
    ::::::::::::::
    testexec2.pl
    ::::::::::::::
    #!/usr/bin/perl
    exec($^X,"testexec3.pl") or print "exec failed - $!\n";
    print "Done $0\n";
    ::::::::::::::
    testexec3.pl
    ::::::::::::::
    #!/usr/bin/perl
    `sleep 3`;
    print "Done $0\n";
    
    On unix, things act as expected: testexec.pl waits for testexec2.pl to finish (with testexec2.pl being replaced with testexec3.pl). But on windows, testexec.pl does NOT wait for testexec2.pl/testexec3.pl to finish. Is there a way to get Windows to act the same as unix? The windows behaviour does not seem correct...

    FYI: I'm trying to avoid using system() instead of exec() because then I open a can of worms regarding the quoting of arguements to the programs being exec()'d (the arguements themselves may contain quotes and/or spaces, and going through the shell on the two different OS's is a whole lot of extra code I can avoid if exec() would just act right :-)

    Aaron


[Offer your reply]
New Meditations
RFC for users of Locale::Maketext::Lexicon
on Nov 23, 2008 at 06:47
0 direct replies by clinton
    Hi all

    I'm a co-maintainer of Locale::Maketext::Lexicon and I'd like to make a change to the format of the .po file created by Locale::Maketext::Extract / xgettext.pl.

    Currently it writes out each entry in the .po file as:

    
        #: $filename_1:$line $filename_2:$line ...
        #. (vars passed to maketext sub)
        msgid "string to translate"
        msgstr ""
    
    

    However, when I edit the file with POEdit, it rewrites the file as:

    
        #. (vars passed to maketext sub)
        #: $filename_1:$line 
        #: $filename_2:$line ...
        msgid "string to translate"
        msgstr ""
    
    

    ... which causes a large unneccessary diff.

    Looking at the gettext manual, having the vars comment before the file location seems to be consistent, but having the file references on new lines is controlled by the option --no-wrap. However, Locale::Maketext::Extract already wraps the msgids, so the behaviour is currently inconsistent.

    What I'd like to know is: can I just make this change, or would it affect you with whatever client you use for editing the .po files? Should I be providing output format options instead?

    thanks

    Clint


[Offer your reply]
New Monk Discussion
Free Nodelet Hack: Floating Chatterbox
on Nov 23, 2008 at 04:11
1 direct reply by ccn
    Put the code below in your FreeNodelet and you get floating Chatterbox.

    Two buttons [-] and [^] appear on the header of CB nodelet.

    • [-] folds/unfolds chatterbox
    • [^] detach/attach chatterbox from nodelet table. You can move detached chatterbox over screen dragging it by it's header.

    I've tested it in FF3 only

    Update: a couple of bugs was fixed


[Offer your reply]
Vulnerability discovered in cbstream plogin
on Nov 17, 2008 at 10:11
1 direct reply by ambrus

    Yesterday, I found two vulnerabilities in cbstream that have been there from almost the start. As you may know, cbstream (then called cbupstream) is a bridge that allows you to talk on the perlmonks chatterbox using any IRC client. This requires a login: you have to tell to cbstream about your perlmonks account name and password. There are two modes of login in cbstream: normal login remembers your account details only until you leave the IRC channel, whereas persistent login remembers them until the bridge is shut down and recognizes you when you enter the channel again. This means cbstream has to know someone entering the channel is the same user as the one who logged in persistently, but the mechanism how it did this was buggy. This bug could have allowed someone to send public perlmonks chatter or private messages in the name of anyone who used the persistent login feature.

    I have temporarily disabled the persistent login feature yesterday, so now cbstream users have to login each time they enter the channel. This closes the vulnerability.

    Kudos to tomaw and jilles who educated me on the workings of the hyperion irc server and thus found these bugs.

    The good news is that there is a secure way to implement persistent login with very little user-visible change. I'll do this when I have time (don't hold your breath) and post an update as a reply here when I've done so.


[Offer your reply]
Login:
Password
remember me
password reminder
Create A New User

Community Ads
Chatterbox
and all is quiet...

How do I use this? | Other CB clients
Other Users
Others chilling in the Monastery: (14)
moritz
wfsp
atcroft
ajt
castaway
herveus
ccn
Eyck
clinton
NodeReaper
Perlbotics
linuxer
dark314
motzi
As of 2008-11-23 13:22 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Snippets Section
Code Catacombs
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Perl Buzz
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Planet Perl
Use Perl
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Global warning is an act of:

Man
God
dog
Sheep
Zod
-W
other

Results (327 votes), past polls