Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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
need a consultant
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 29, 2015 at 18:40
    I want to contract a Perl Web Dev. mail@avatarengineer.com
Perl/Tk, PAR::Packer and Menus
3 direct replies — Read more / Contribute
by dbarstis
on Jul 29, 2015 at 17:14

    Kind monks of the monastery, I have what should be a simple issue to resolve but am having trouble finding a solution. I have a simple script using Tk with a menubar. The script runs fine when invoked with the perl command but the menubar is no where to be seen when an executable is built with pp. This is on a Windows machine with Strawberry Perl 5.14.2 and Tk 804.033 (actually the DWIM install). Any and all wisdom would be greatly appreciated.

    use Tk; my $mw = MainWindow->new; my $menubar = $mw->Menu(); $mw->configure( -menu => $menubar ); my $file = $menubar->cascade( -label => '~File' ); $file->command( -label => '~Quit', -command => sub { exit }, -accelerator => 'Ctrl-Q' ); $mw->bind( '<Control-q>', sub { exit } ); $mw->MainLoop(); exit;
Fork or Thread?
1 direct reply — Read more / Contribute
by beanscake
on Jul 29, 2015 at 16:44

    Hello Monks,

    I have chunks of data that i am going to upload to Database which can take days to finish upload , i think if i can partition the arrays of data to be uploaded into some part while i spawn process to save each allocated @array data, i think it may save me some time please i need help with this Threads or Fork please advice

    use strict; use warnings; my @orig = 1..2500; my $numberofarray = scalar @orig; my $arrs = 100; # Partition #print $arrs; sub Partition_Array_data { my @arrs; push @{$arrs[$_ % $arrs]}, $orig[$_] for 0..$#orig; if (my $pid = fork) { waitpid($pid, 0); } else { if (fork) { exit } else { thread_dbSave(\@arrs); } } } sub thread_dbSave { # this function will handle the saving my @arrayofsplit = @{$_[0]}; print join ' ', @$_, "\n" for @arrayofsplit; } &Partition_Array_data();
how to sum over rows based on column headings in perl
3 direct replies — Read more / Contribute
by angerusso
on Jul 29, 2015 at 16:02

    I have a datafile which has only "W" and "Ms" entries. As in the example, I want to count number of A's which have "M" appearing atleast once over unique column names.

    Gname G1 G1 G1 G1 G2 G2 G3 A W W M W W M A W W W W W W A W W W W W W B W W W W W M B M W W W W M C M M M W W W C M W W M M W The output should be: Gname G1 G2 G3 A 1 0 1 B 1 0 2 C 2 1 0

    I have written the following code to write the header row but I am very confused how should I start counting over blocks/chunks of data like I want. Can anyone help?

    open(INPUTR,"<$mfile") || die "Can't open \$mfile for reading. \n"; while($line=<INPUTR>){ chomp $line; @toks = split(/\t/,$line); $countm = 0; if ($toks[0] =~ /^Gname/){ $k = 0; # loop over the header row to get the unique "Gname"s for $j (1..@toks-2){ $i = $j+1; if ($header[$i] != $header[$j]){ $k++; $name[$k] = $header[$j]; } } for $i (0..$k){ $hash{$toks[0]}{$name[$k]} = $name[$k]; } } } close(INPUTR);
What is greedy and lazy Matching in perl
6 direct replies — Read more / Contribute
by shankonit
on Jul 29, 2015 at 13:19

    Please help me to understand these two concepts in regular expression like . and .*.

    Thank u in advance for your time taken to read and answer

INIT {$SIG{__DIE__} and Getopt::Long
4 direct replies — Read more / Contribute
by demichi
on Jul 29, 2015 at 13:16
    Hi all

    I am normally using the following line to capture the die output into a logfile.

     INIT {$SIG{__DIE__}=sub {LOG_MSG("normal",3,"GENERAL","Script died: $_[0]") and close LOG;}}

    Now I am using also Getopt::Long. I don't want to have a logfile generated if somebody is chosing the wrong parameter. Therefore I let the script die with an usage output.

    Unfortunately if somebody choses a wrong getopt parameter now - I get a log error message because of the INIT-"die" setting as the log file is not opened yet.

    Example:
    G:\development\bin>x.pl -x > 4,GENERAL,Script warning: Unknown option: x print() on unopened filehandle LOG at G:\development\bin\x.pl line 45. + ### Version:2.0.0 NAME xxx > 3,GENERAL,Script died: 1 at G:\development\bin\x.pl line 14. ### > 4,GENERAL,Script warning: print() on unopened filehandle LOG at G:\d +evelopment\bin\x.pl line 45. ### print() on unopened filehandle LOG at G:\development\bin\x.pl line 45. + ### 1 at G:\development\bin\x.pl line 14. ### G:\development\bin>

    Every line marked with "###" at the end I do not want to have as output to STDOUT.

    Do you have an ideas how can fix it? Thanks.

    kind regards de Michi

    Code:
    use strict; use warnings; use Getopt::Long qw(:config no_ignore_case bundling); # Get options / my $VERSION = "2.0.0"; INIT {$SIG{__DIE__}=sub {LOG_MSG("normal",3,"GENERAL","Script died: $_ +[0]") and close LOG;}} INIT {$SIG{__WARN__}=sub {LOG_MSG("normal",4,"GENERAL","Script warning +: $_[0]")}} # Check Flags my $flag_help; my $flag_version; my $flag_config; GetOptions ( 'h|help' => \$flag_help, 'V|VER' => \$flag_version, 'c|config=s' => \$flag_config, ) or die USAGE(); # Check flags and print usage if ($flag_version) { print "Version: $VERSION\n"; exit; } if ($flag_help) { USAGE(); exit; } open(LOG,"> SCRIPTLOG_FILE") or die ("Can't open SCRIPTLOG_FILE: $!\n" +); close LOG; ### subs sub LOG_MSG { my $par_LEVEL = shift (@_); my $par_SEVERITY = shift (@_); my $par_FUNCTION = shift (@_); my @line = @_; print "> $par_SEVERITY,$par_FUNCTION,@line\n"; print LOG "$par_SEVERITY,$par_FUNCTION,@line\n"; } sub USAGE { my ($message)=<<'MESSAGE'; NAME xxx MESSAGE print "Version:${VERSION}\n$message"; }
calculating length of the string
2 direct replies — Read more / Contribute
by GSperlbio
on Jul 29, 2015 at 05:24
    Im having sequence "CUGUACAGCCUCCUAGCUUUCC" in the file "rna.txt" i need to get the length of the sequence as 22 instead im getting 23. can anyone help me to correct this error?? this is my code: #!usr/bin/perl use warnings; open (RH, "<rna.txt") || die "cant open the file"; my $arr2 = <RH>; print "rna sequence is $arr2"; $len2= length($arr2); print $len2;
How to get the process Id
6 direct replies — Read more / Contribute
by vasuperl
on Jul 29, 2015 at 03:34
    Hi, I want to get the process id for the command executed in the command prompt. For example I want to execute command of "tcpdump -i any -w filename.pcap &" in the linux machine from my windows PC. Now I want to get the process id of that command. I have done telnet connection to that linux machine and able to execute that command. But i was not able to get the process id of that command to kill that process. I am new to perl. Please help me on this
Comparing specific columns from 2 files
4 direct replies — Read more / Contribute
by arunsriniv
on Jul 29, 2015 at 02:53

    Hello, I am trying to compare specific columns in 2 files so see whether the contents in one file (File1.txt) which is a master file is exact with another file (File2.txt) which is a subset of File1.

    For Example: File1.txt (Master file)

    Status1,Name1,Source1,Destination1

    Status2,Name2,Source2,Destination2

    Status3,Name3,Source3,Destination3

    .....

    .....

    File2.txt (Subset of File1.txt)

    Status1,Name1,Source1,Destination1

    Status2,Name2,Source2,Destination2

    Now, I am trying to compare only specific columns in File1 with File2 say ignore Status column and compare only the remaining columns for exactness. Any ideas are appreciated? My current code is to compare all columns between 2 files for exactness.

    my @cur_data=<FILE1>; close (FILE1); my @org_data=<FILE2>; close (FILE2); foreach $org_data(@org_data) { $flag= 1; foreach $cur_data(@cur_data) { chomp ($cur_data); chomp ($org_data); if ( $cur_data eq $org_data ) { $flag= 0; last; } } if ($flag == 1) { print " \n $org_data -->failed\n"; last; } } return $flag;
Call external script via ssh with Control::CLI, get output to calling script window
1 direct reply — Read more / Contribute
by ImJustAFriend
on Jul 29, 2015 at 02:02

    I am 100% sure I'm missing something real basic here, but after a week of trial and error, I think it's time to ask you fine folks for help.

    I am creating an automation script for work that will run from Windows laptops. It will use the Control::CLI module to ssh to the target remote servers and do the work. The script I created works wonderfully, with one minor annoyance. At a certain point in my script, I have to launch an external script that resides on one of the target servers and monitor it's progress so I know when to move on. The external script does provide feedback as it runs, which I do monitor... but my users want to see that feedback when the script is running. An example of what they currently see from my script is:

    Are you ready to let it run (y/n)? y Pre-loading started at: Tue Jul 28 16:10:13 UTC 2015 Please wait for pre-loading to finish... X records loaded into system in N seconds... X records loaded into system in N seconds... ...

    What they are asking for is to show the output of the pre-loader script, like:

    Are you ready to let it run (y/n)? y Pre-loading started at: Tue Jul 28 16:10:13 UTC 2015 Please wait for pre-loading to finish... File1 loaded... File2 loaded... ... X records loaded into system in N seconds... X records loaded into system in N seconds... ...

    The "FileN loaded" lines are printed out by the pre-loader script. The command I send to the server to launch the pre-loader looks like this:

    $s1_output = $s1_cli->cmd("/path/to/pre-loader.pl arg1 arg2 2>&1");

    How can I get the output of pre-loader.pl to display in my calling script window?

    Thanks in advance!!


Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
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.
  • Please read these before you post! —
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (8)
    As of 2015-07-30 00:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (269 votes), past polls