good chemistry is complicated,and a little bit messy -LW 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
 Can I auto-save and restore global variables? 2 direct replies — Read more / Contribute by davehorsfall on Jul 24, 2014 at 17:39 Perl 5.10 on MacBook 10.6.8 (Snow Leopard). Is there a way to auto-save and restore global variables, such as those found in Data::Dumper? I envisage something like: use Data::Dumper; $Data::Dumper::blah = 0; # Set defaults$Data::Dumper::fred = 'xyz'; ... if ($i_am_debugging_this_bit) { SAVE(Data::Dumper);$Data::Dumper::blah = 1; # Override these for a bit $Data::Dumper::fred = 'nerd'; ... RESTORE(Data::Dumper); # Put them all back } [download] Convertion Perl Script to Exe with PAR::Packer pp 2 direct replies — Read more / Contribute by marchiore on Jul 24, 2014 at 16:32 I'm trying to convert a perl script to a executable file with PAR::Packer pp with the command (Windows 7 64 bits):  "pp -o teste.exe gmail_att.pl" [download] but i'm receiving the message:  "# Use of runtime loader module Module::Runtime detected.Results o +f static scanning may be incomplete." [download] I search for this message on the internet but without success The script:  printf("Iniciando o envio de e-mails... \n"); use strict; use Try::Tiny; use IO::All; use Email::MIME; use Email::Sender::Simple qw(sendmail); use Email::Sender::Transport::SMTP::TLS; use Spreadsheet::XLSX; use File::Basename; my$diretorioScript = dirname(__FILE__); my $excel = Spreadsheet::XLSX->new( "$diretorioScript\\jofalista.x +lsx", ); my $diretorio = "$diretorioScript\\arquivos\\"; my $email = ""; my$nome = ""; opendir(diretorio, "$diretorio"); my @lista = readdir(diretorio); closedir(diretorio); foreach my$arquivo(@lista) { $email = "";$nome = ""; if ($arquivo ne "." &&$arquivo ne ".."){ # print $arquivo; # rotina para buscar dentro do arquivo xls qual o email # de destino do arquivo foreach my$sheet ( @{ $excel->{Worksheet} } ) {$sheet->{MaxRow} ||= $sheet->{MinRow}; foreach my$row ( $sheet->{MinRow} ..$sheet->{MaxRow} + ) { $sheet->{MaxCol} ||=$sheet->{MinCol}; foreach my $col ($sheet->{MinCol} .. $sheet->{Max +Col} ) { my$cell = $sheet->{Cells}[$row][$col]; if ($cell) { #printf( "( %s == %s ) \n", "$cell->{Val}. +pdf",$arquivo ); if("$cell->{Val}.pdf" eq$arquivo){ $nome =$cell->{Val}; my $emailCell =$sheet->{Cells}[$row][ +$col+1]; $email =$emailCell->{Val}; #printf("%s", $email); } #printf( "( %s , %s ) => %s\n",$row, $col +,$cell->{Val} ); } } } } if($email ne ""){ printf("Processando o arquivo$arquivo para o email: $+email \n"); # Create and array of email parts. # Here i have 2 attachments ( an image and a pdf file) + and a text message. my @parts = ( Email::MIME->create( attributes => { filename => "$arquivo", content_type => "application/pdf", encoding => "base64", disposition => "attachment", name => "$arquivo", }, body => io( "$diretorio$arquivo" )->all, ), Email::MIME->create( attributes => { content_type => "text/html", }, body => "Ola$nome este é um e-mail teste da J +OFA", ) ); # Create the email message object. my $email_object = Email::MIME->create( header => [ From => 'marchiore.matheus@gmail.com +', To =>$email, Subject => "Certificado $nome", content_type =>'multipart/mixed' ], parts => [ @parts ], ); # Create the transport. Using gmail for this example my$transport = Email::Sender::Transport::SMTP::TLS->n +ew( host => 'smtp.gmail.com', port => 587, username => 'marchiore.matheus@gmail.com', password => '' ); # send the mail try { sendmail( $email_object, {transport =>$transpo +rt} ); } catch { warn "Email sending failed: $_"; }; } } } printf("Pressione ENTER para Finalizar... \n"); chomp( my$input = ); [download] Cannot subclass Gearman::XS::Client 2 direct replies — Read more / Contribute by incubusaurus on Jul 24, 2014 at 15:31 Hi, I've been trying to create a simple subclass of Gearman::XS::Client, but seem unable to do so. I can instantiate the subclass, but the object is not of the correct class: use Test::More; use strict; use warnings; { package My::Gearman::Client; use parent 'Gearman::XS::Client'; sub foo {} } my $gm = My::Gearman::Client->new; isa_ok($gm, 'Gearman::XS::Client'); # Pass isa_ok($gm, 'My::Gearman::Client'); # Fail can_ok($gm, 'foo'); # Fail [download] The code works as expected if I substitute Gearman::XS::Client with another module, such as JSON::XS. I've tried use parent, use base, manually modifying @ISA, and using extends from Mouse. I'm assuming that the problem is caused by Gearman::XS::Client, buy why? Why is cpan's option INSTALLDIRS=site putting modules in ~/perl5? 1 direct reply — Read more / Contribute by Steve_BZ on Jul 24, 2014 at 10:45 Hi Guys, I've just performed a rebuild that I have perfomed many, many times before, accepting the cpan defaults, and suddenly subsequent modules are not seeing earlier modules, like dependencies. This turns out to be because cpan is mysteriously putting the modules in ~/perl5/lib/perl5, which is not in @INC. Not surprisingly, subsequent modules don't see their dependencies when installed this way. "Can't find CPAN::Meta::Requirements.pm" is a common error message. It looks as though I've not set up cpan correctly. Just copying the modules to /usr/share/perl/5.14.2/ works for some modules, but clearly not for all. How to set up cpan correctly? I'm using Kubuntu 12.04 LTS. Thanks for your help. Regards Steve. Hacking a source filter into the #! line 2 direct replies — Read more / Contribute by dcmertens on Jul 24, 2014 at 10:41 I recently wrote a module that extracts my Perl code from a LyX document. (LyX is a WYSIWYG LaTeX editor, if that helps provide some context.) Originally I wrote it as a source filter that was meant to be invoked on the command line, as perl -MyX my-document.lyx [download] (Yes, the module is called yX.pm.) However, it'd be really cool if I could just type perl my-document.lyx [download] Perl is pretty flexible, and I thought that maybe I could get away with throwing a few garbage lines at it before getting to the source filter usage line. So, I tried adding something to the LaTeX preamble, resulting in the following sort of stuff at the beginning of the .lyx file: #LyX 2.1 created this file. For more info see http://www.lyx.org/ \lyxformat 474 \begin_document \begin_header \textclass article \begin_preamble %ignore; use yX; ... [download] Unfortunately, perl is not quite liberal enough: Number found where operator expected at test.lyx line 2, near "lyxform +at 474" (Do you need to predeclare lyxformat?) Backslash found where operator expected at test.lyx line 3, near "\" (Missing semicolon on previous line?) Backslash found where operator expected at test.lyx line 4, near "begi +n_document \" (Missing semicolon on previous line?) Backslash found where operator expected at test.lyx line 5, near "begi +n_header \" (Missing semicolon on previous line?) Operator or semicolon missing before %ignore at test.lyx line 7. Ambiguous use of % resolved as operator % at test.lyx line 7. syntax error at test.lyx line 2, near "lyxformat 474" BEGIN not safe after errors--compilation aborted at test.lyx line 7. [download] The astute observer will notice the very top line begins with a hash character. Furthermore, LyX does not examine the content of this line, so I can change it to something like this: #!perl -MyX [download] Unfortunately, Perl does not let you specify a module in the #! line. :-( Then I struck upon this discussion of the problem on the Perl Porters mailing list. Ric's solution is to use the -d switch, which would look like this: #!perl -d:MyX [download] Lo! it works (after renaming the module, of course)! So my question: If I manage to create a module/extension for LyX that adds this shebang line, would I be a horrible person for exploiting this sort of hack? Unable to write output to file taken as input from command line 3 direct replies — Read more / Contribute by zing on Jul 24, 2014 at 08:47 Hi all, So I have this code which takes input and output file from command line, then writes a certain output to the output file (Only the relevant portion shown here due to privacy issues):  use strict; use warnings; use autodie; # check that two arguments have been passed die "usage: $0 input output\n" unless @ARGV == 2; my$infile = shift; my $outfile = shift; open my$in, "<", $infile; open(DATA,$in); open my $out, ">",$outfile; ins split /,\s*/ for ; print $out "%-4s: %20s, %-8s %6s\n",$_->[0], qq($_->[0]$_->[3]) +, $_->[2],$group{$_->[2]}; close$in; close $out; [download] The problem is that it isnt writing anything to the output file. Due to certain reasons I want to read in the input file in format, so that cant be done away with. Please help$1 returning value from previous match 1 direct reply — Read more / Contribute by wistephens on Jul 24, 2014 at 08:43 Monks, I have a couple of matches that I'm using to extract data from a string: At the completion of the first match, $orderNameString = "Injection For Lymphangiography" At the completion of the second match,$1 still contains the contents of the previous match. What's happening here? # Injection For Lymphangiography[75999] $orderName =~ /^(.*)$(\d*)$/; my$orderNameString = 1; # Lentigo maligna melanoma [172.9]diagnosis =~ /^(.*)\s$(\d*)$/; my $diagnosisString =$1; [download] Thanks, Bill channel blocking 2 direct replies — Read more / Contribute by gopalreddy on Jul 24, 2014 at 07:02 I have a perl script to connect to remote host using SSH2 and execte commands. Script creates connection, opens channel, executes the commands and closed channel and connection. This script is called by some scheduler process which wil execute at 30 sec interval. it is working fine, but has script doesn't execute the commands when the remote SSH is reset(down and up). It works fine when i restart the scheduler. Can any one help? String extract 2 2 direct replies — Read more / Contribute by kepler on Jul 24, 2014 at 06:55 Hi, I'm having some troubles to extract an expresiion from a $line. The type of expression is, for example: KP_what_I_want (space) or KP_what_I_want( or KP_what_I_want ( or KP_what_I_want + etc... I'm using: my ($exp) = \$line =~ m/ KP_ # Required (.*) # Capture Desired Output (?:\s)? # Optional - Do not capture (?:\()? # Optional - Do not capture /xi; >/code> It's not working... it extracts the all expression ( without the KP_) Any ideas? Thanks, Kepler CPAN Module Installation (aka Oh, God, Here We Go Again) 8 direct replies — Read more / Contribute by marinersk on Jul 23, 2014 at 23:14 New computer. Most but not all installation complete. Decided I'd like to try my hand at automating Windows stuff (mouse, keyboard, etc.). The tools out there are nice but gosh wouldn't it be nice to have some more direct control. A quick Google search turns up references to Win32::GuiTest. Sounds about right. Let's go get it. And then and old, familiar panic starts to set in. OMG I am going to have to learn again how to install a CPAN module. :: sigh :: Heaven help me. And I have my usual measure of first-attempt success: S:\Steve\Dev\gscripter>perl -MCPAN -e 'install Win32::GuiTest' It looks like you don't have a C compiler and make utility installed. + Trying to install dmake and the MinGW64 gcc compiler using the Perl Package M +anager. This may take a a few minutes... ppm.bat install failed: Can't find any package that provides MinGW64 It looks like the installation of dmake and MinGW64 has failed. You w +ill not be able to run Makefile commands or compile C extension code. Please +check your internet connection and your proxy settings! Can't find string terminator "'" anywhere before EOF at -e line 1. [download] I'm almost ready to just give up on Perl. After all this time, you'd think this stuff would have gained more ground in the usability space. Problem is, all the Perl geeks who use CPAN use it enough to remember all the tips, tricks, gotchas, pre-reqs, etc. So y'all have only improved the stuff where you have felt it was needed. (This is not a complaint. It is merely an observation and a conclusion.) It's too late and I'm not 18 anymore. Guess I'll put this down and pick it back up another day.

text here (a paragraph)

and:  code here 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.
• 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: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-07-24 23:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?