Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

The Monastery Gates

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

New Questions
Mail - 32bit vs 64bit
3 direct replies — Read more / Contribute
by krausr
on Mar 22, 2017 at 08:57

    I have a script that emails me details from a file. The script works fine in a 32-bit version of Activeperl, but does not run using a 64-bit version. It seems to crap out on this line:

    $smtp->mail($email_from); # sender's address
  • Why would that ever be a case?
  • How can I fix this to work on either version?
  • use Net::SMTP; use Win32::EventLog; $summary = ''; $extra = ''; $begin_summary = 0; $data_file = "C:/Logs/myfile.log"; open(IN, $data_file) || die("Could not open file!"); @raw_data = <IN>; close(IN); for my $row (@raw_data) { if ( $row =~ /\s+Total\s+Copied\s+Skipped\s+Mismatch\s+FAILED\s+Ex +tras\s+/ ) { $begin_summary = 1; } if ( $begin_summary ) { $summary .= $row; } if ($row =~ /\s+Ended \: /) { #print "Exiting loop\n"; last; } } write_event(900, EVENTLOG_INFORMATION_TYPE, $summary); send_email("My Big Fat Notification - " . $ENV{COMPUTERNAME}, "$extra\ +n$summary"); sub send_email() { my ($subject, $body) = @_; my $email_from = 'fromster@frobot.com'; my $email_to = ('toster@frobot.com'); my $smtp = Net::SMTP->new('smtpserver.frobot.com'); # Connect to a +n SMTP server $smtp->mail($email_from); # sender's address $smtp->to($email_to); # Recipient's address $smtp->data(); # Start the mail # Send the header. $smtp->datasend("To: $email_to\n"); $smtp->datasend("From: $email_from\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); MORE CODE AFTER THIS...
Accessing the hash name in perl
4 direct replies — Read more / Contribute
by Sonali
on Mar 22, 2017 at 08:11

    Hello Perl monks,

    I am a Perl newbie

    I am try to get the name of the hash which is in another Perl file, and then access the hash elements, but when I run my program I am getting these errors

    Use of uninitialized value $line in pattern match (m//) at test.pm line 17.

    Use of uninitialized value $typ_s in string at test.pm line 20.

    My code goes like this

    package hash; use strict; use warnings; $test = { 'hash1' => { 'paramA' => '00' , 'paramB' => 'FF' , }, 'hash2' => { 'paramA' => '01' , 'paramB' => '02' , }, 'hash3' => { 'paramA' => '00' , 'paramB' => '03' , }, };

    This the Perl file which contains the hash that needs to be extracted

    This is the Perl script I have written to extract the hash

    #!/usr/local/bin/perl use strict; use warnings; Generate(); sub Generate { Process_File('hash.pm'); } sub Process_File { my $filename = shift; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $line; $line =~ m/\'hash1\'/; my $typ_s = $line->{paramA}; my $paramB = $line->{paramB}; print "$typ_s"; }

    Help me!

CPAN::Mini on a diet
2 direct replies — Read more / Contribute
by glasswalk3r
on Mar 21, 2017 at 19:14

    Hello follow monks,

    Are you aware of any technique to reduce the size of a CPAN::Mini repository?

    I was checking my local mirror here and it is around 4.9Gb on a OpenBSD 6 box with FFS.

    Taking a look at my ID under authors directory, I see that there are tarballs over there that are not even listed on my PAUSE account anymore (might be some issue regarding mirror synchronization). Anyway, I guess that for my purposes I could use only the latest available distribution for everybody.

    A quick check on CPAN::Mini and minicpan documentation doesn't show anything that would help with that.

    Is there any trick to take care of it?

    Thanks!

    UPDATED

    I tried this:

    Still pending to validate if it didn't break anything...

    Anyway, I was able to reduce it to 3.0Gb from the initial 4.9Gb...

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Directory Structure Recommendations
3 direct replies — Read more / Contribute
by Ossie
on Mar 20, 2017 at 08:14

    Hi Folks

    As a newbie to Perl I'm seeking guidance about directory structure that is good practice, as I've not yet found it in the various documents I've looked at.

    My primary objective is to run a program (Mapivi) under Perl on a Windows PC (I'll write my own additional code at later stage).

    I've successfully installed Strawberry Perl and downloaded Mapivi together with other necessary files such as Perl/Tk and Image-MetaData-JPEG.

    So what (if any) additional directories should I create to hold the various files when I unpack them, prior to running the usual sequence of Makefile & Test & Install, and should the resulting files be put into specific directories?

    If there are existing publications covering this then I'd be grateful if you point me in their direction, as well as giving the benfit of your experience.

    Related follow-on questions may then be about what has to be manually added to PATH and @INC

    Thanks

how to align the label and entry text box in my tk GUI
9 direct replies — Read more / Contribute
by fsmendoza
on Mar 20, 2017 at 03:22

    Dear Perlmonk experts,

    I'm designing my simple GUI and i could not find a way to get rid of the spaces between the label and entry box in my output GUI and align them. Please advice on what will be the best way to do this.

    Thank you.

    use strict; # module to must always declare variabl +es before you use them use warnings; # module to show where is the error use Tk; # module for the Windows GUI my $mainwindow = MainWindow->new(); $mainwindow->geometry("600x150"); $mainwindow->title("Window"); # Disable the window Resize $mainwindow->resizable(0,0); # Menu display option my $main_menu = $mainwindow->Menu(); $mainwindow->configure(-menu => $main_menu); #File my $file_menu = $main_menu->cascade(-label=>"File", -underline => 0, - +tearoff=>0); $file_menu->command(-label=>"New", -underline=>0, -command=>sub{exi +t}, -state => 'disabled'); $file_menu->command(-label=>"Exit", -underline=>0, -command=>sub{ex +it}); # About $main_menu->command(-label=>"About", -command=>sub{$mainwindow->messag +eBox(-title=> "About", -message=>"Version 3.0.0", -type => "ok")}); # text variable my $label_firstname; my $entry_firstname; my $label_lastname; my $entry_lastname; my $label_loginid; my $entry_loginid; my $button_add; # -anchor => 'e' | 'w' | 'n' | 's' | 'ne' | 'nw' | 'se' | 'sw' | 'cen +ter' # top ################################ # nw n ne # # # # w center e # # # # sw s se # ################################ # bottom $label_firstname = $mainwindow->Label(-text => 'Firstname:')->pack (-a +nchor => 'nw'); $entry_firstname = $mainwindow->Entry(-width => 35,-text => 'Firstname +')->pack (-anchor => 'n' ); $label_lastname = $mainwindow->Label(-text => 'Lastname:')->pack (-anc +hor => 'nw'); $entry_lastname = $mainwindow->Entry(-width => 35,-text => 'Lastname') +->pack (-anchor => 'n'); $label_loginid = $mainwindow->Label(-text => 'Login ID:')->pack( -anch +or => 'nw'); $entry_loginid = $mainwindow->Entry(-width => 35,-text => 'loginID')-> +pack (-anchor => 'n'); $button_add = $mainwindow->Button(-text => 'Add New User', -command=>s +ub{exit})->pack(-anchor => 'se'); MainLoop();
Using ActivePerl and Strawberry simultaneously
3 direct replies — Read more / Contribute
by dhannotte
on Mar 20, 2017 at 00:20

    I recently upgraded my version of 64-bit ActivePerl from version 5.10.1.1007 to 5.22.2.2203, and am having tons of problems with it.

    I'd really rather jump to Strawberry, but I'll have to test it first on each of the critical Perl apps I run on a daily basis.

    Can I install the portable version of Strawberry and test it out while continuing to use the ActivePerl version for production work?

Fastest way of XML -> perl structure
5 direct replies — Read more / Contribute
by sectokia
on Mar 19, 2017 at 18:16

    Hi wise monks,

    What is the fastest way to go from XML to perl? I have 16MB+ XML files that are taking many seconds.

    I have tried XML::Simple XML::Fast and XML::Bare, but all are surprisingly slow. Normalised its: Simple 1.0, fast 0.55, bare 0.4. But even then, that seems rediculously slow, with 3GHz machines still taking 10+ seconds.

    In comparison, I wrote a dodgy C program that takes the XML and outputs a eval'able perl literal structure of nested array/hashes. Running the program and eval'ing the output is nearly 3x faster than xml::bare!

    However I feel like I am re-inventing the wheel here (my dodgy program doesn't support attributes) and people must know a fast way to go from xml to perl already?

    My other question is: Since eval is where most of the processing time is, is there some sort of 'direct' memory format for perl? For example: I would like my C program to output a 'memory blob' of nested arrays/hashes/scalers that would go straight into Perl, without having to 'parse'/'eval' anything.

    The structures I want to put in are mostly like this:

    {'elements' => [ 'element' => { 'item' => 'value', 'item2' => 'value' } , 'element2' => { 'item' => 'value', 'item2' => 'value' } , ] , 'elements2' => [ 'element' => { 'item' => 'value', 'item2' => 'value' } , 'element2' => { 'item' => 'value', 'item2' => 'value' } , ] }
counting protein residues
4 direct replies — Read more / Contribute
by peing
on Mar 19, 2017 at 00:54
    output of Jpred is --------HHHHHH-----HHHHHHHH------ (H stands for helix), write a perl script to count the number of residues in the helices. How do I do this? This is my first time using perl
about Gearman::Client options
No replies — Read more | Post response
by liuweichuan
on Mar 17, 2017 at 21:25
    hi everyone,

    i have a problem one Gearman::Client or Gearman::Task. for this way,

    Gearman::Task->new($func, $arg, \%options)

    i set the options "uniq" and "timeout", but it cannot work,

    use Gearman::Client; my $client = Gearman::Client->new; $client->job_servers('127.0.0.1:7003'); my $taskset = $client->new_task_set; $taskset->add_task('fun' => undef ,{ uniq => 1, on_complete => sub{print ${$_[0]}}, timeout => 2, } ); $taskset->wait;

    -----------

    use Gearman::Worker; my $worker = Gearman::Worker->new; $worker->job_servers('127.0.0.1:7003'); $worker->register_function('fun' =>\&w); $worker->work while 1; sub w{ print "3"; return 3; }

    i want to resold 2 problem, 1) run the same names of functions on workers in parallel, so i try the option "uniq", but it's not any result. 2) runing when the client call a function not existed, so i try the timeout, but ..

    or help me how to get functions registed on server.

    Plz help me, thx
Script failed with certain value in the variable
5 direct replies — Read more / Contribute
by mamoru0916
on Mar 17, 2017 at 20:58

    I'm running perl on windows with active perl 5.24 x64. This mystery issue is really bothering me. So, I'm here to seeking for some wisdom.

    Lets call my script getopt.pl and it takes the input and doing something. However, whenever the value in the variable is "E48.2", the value is creating issue causing the script to fail miserably.

    Input: 1. getopt.pl --platform=1 --version=E48.1 ..... ok 2. getopt.pl --platform=1 --version=E48.2 ..... Failed 3. getopt.pl --platform=1 --version=48.2 ..... ok 4. getopt.pl --platform=1 (script find version value E48.2) ... failed Sample code: use Getopt::Long; my $platform = 0; my $version = undef; my $suffix = undef; my $flag1 = 0; my $flag2 = 0; GetOptions ('platform=i' => \$platform, 'version=s' => \$version, 'suffix=s' => \$suffix, 'flag1' => \$flag1, 'flag2' => \$flag2,); if ($platform == 1) { if (!defined($version)) { Find version number!! $version = E . "$valuefind"; ($version will be E48.2) } print "Find version: " . $version . "!\n"; if (!defined(Suffix) && defined($version)) { Find suffix value, let's say suffix is F!! } print "Find suffix: " . $suffix . "!\n"; } Output for each input is like: 1. Find version: E48.1! Find suffix: F! 2. Find version: E48.2! Use of uninitialized value $suffix in concatenation (.) or string a +t getopt.pl. 3. Find version: 48.2! Find suffix: F! 4. Find version: E48.2! Use of uninitialized value $suffix in concatenation (.) or string a +t getopt.pl.

    For some reason, when the value in $version is E48.2, the script can't enter the last if clause to find the $suffix value. Tried a few other number all seems to be okay....E48.3, E48.4 .. 5.. 6.. E74.0 E64.5 ... etc

    Chris

Wrap multiple programs
2 direct replies — Read more / Contribute
by jnarayan81
on Mar 17, 2017 at 20:41

    How to wrap multiple programs in one main program?

    perl Main.pl plot -file FILE -length LENGTH

    perl Main.pl calc -length 20 -width 30

    So Main.pl contains two sub-programs 'plot' and 'calc'. User can call anyone of them, based on their need.

    ################# PLOT program here #!/usr/bin/perl -w use Getopt::Long; my $data = "file1"; my $length = 4; my $verbose; GetOptions ( "length=i" => \$length, "file=s" => \$data, "verbose" => \$verbose ); if (!@ARGV) { print "$0: Argument required.\n"; exit 1 } my $fh = read_fh ($data); while (<$fh>) { print "$_\n"; } ##sub here # Open and Read a file sub read_fh { my $filename = shift @_; my $filehandle; if ($filename =~ /gz$/) { open $filehandle, "gunzip -dc $filename |" or die $!; } else { open $filehandle, "<$filename" or die $!; } return $filehandle; } ################# CALC program here #!/usr/bin/perl -w use Getopt::Long; my $width = 5; my $length = 4; my $verbose; GetOptions ( "width=i" => \$width, "length=i" => \$length, "verbose" => \$verbose ); if (!@ARGV) { print "$0: Argument required.\n"; exit 1 } my $total=$width*$length; print $total;
Is it File::Map issue, or another 'helpful' Perl regex optimization?
2 direct replies — Read more / Contribute
by vr
on Mar 17, 2017 at 19:52

    I have a 50 Mb file:

    perl -e "print 'x' x (50*1024*1024)" > x

    Suppose I slurp it and do some matching:

    use strict; use warnings; my $s = do { local ( @ARGV, $/ ) = 'x'; <> }; $s =~ /x/;
    $ /usr/bin/time -f %M perl fmap.pl

    Maximum resident set size reported as 53596 kbytes. Fair enough. Then I learn about File::Map, and do this:

    use strict; use warnings; use File::Map qw/ map_file /; map_file my $s, 'x', '<'; $s =~ /x/;

    105844. Twice as much memory consumed. Actually, I'd expect, quoting POD,

    loading the pages lazily on access. This means you only 'pay' for the parts of the file you actually use.

    -- match consumes a single byte, hence only a "page" was loaded, no? Not the whole file. Otherwise, what's the point of example in synopsis? OK, maybe I'm wrong and Perl's regex engine wants a string in RAM, physically. But, if match was unsuccessful, e.g. $s =~ /y/; then -- 54676. Looks like a copy is made on each successful match:

    $s =~ /x/; $s =~ /x/; $s =~ /x/; $s =~ /x/; $s =~ /x/;

    Then: 310784.

    But not in a loop: $s =~ /x/ for 1 .. 5; Then, again, 105848.

    That's all rather weird. Same happens on Windows, too. (There was another issue, on Windows -- it suddenly refused to map a 'merely' 1 Gb file, and it appears that CreateFileMapping expects a continuous block in virtual memory of required size -- which can either happen or not even during the same day. Doesn't look as usable to me. But perhaps it's not Perl issue.)

    I'm asking, because at first I was enthusiastic about this patch. Now I'm not so sure.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-03-23 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (282 votes). Check out past polls.