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
Accessing 2 multidimensional arrays simultaneously
3 direct replies — Read more / Contribute
by Ppeoc
on May 04, 2016 at 13:17
    Dear Monks, I have 2 multi dimensional arrays @array1 and @array2. @array1 and @array2 have elements in the form,
    $VAR1 = ['1,v,3,4']; $VAR2 = ['3,v,4,t']; ... ... $VARn = ['3,8,0,7']; $VAR1 = ['7,po,0'];
    @array1 and @array2 have the same number of rows but different columns. How can I access each row of both the arrays simultaneously. I want to print $VAR1 of @array1 and $VAR1 of @array2 on the same line. display as eg. 1,v,3,4,7,po,0. This is how I have saved my data into @array1
    while (<$fh>){ last if /^\s*$/; my @data= split(/\s+/,$_); @data = join (",",@data); push @array1, [@data]; }
    This is how I have been accessing elements of 1 2D array
    foreach my $x (@array1) { foreach my $y (@$x) { print $fout1 $y,"\n"; } }
    Any help would be appreciated. Thanks!
Print &
4 direct replies — Read more / Contribute
by meechl
on May 04, 2016 at 13:07

    Hi monks,

    I would simply like to print out the character "&". All my attempts thus far have been futile, including use of "\&" or ascii codes. Thanks for the help!

    Edit: Thanks for the replies! I am running perl on the command line and printing to a file. Here is the code for the out file generation and print statement:

    my $outFile = $outbase . "_temp_stems_RNAcofold.txt"; open(OUT, ">$outFile") or die "Could not open $outFile.\n"; print OUT ">$name\t$compName\n$seq" . "&" . "$compSeq\n";

    Edit 2: Wow, I'm an idiot. Was looking at the wrong output.

Perl6 Threads
1 direct reply — Read more / Contribute
by Anonymous Monk
on May 04, 2016 at 13:03
    I saved "my $thread = Thread.start({ for 1 .. 10 -> $v { say $v }});" from https://docs.perl6.org/language/concurrency#Threads into a file and ran "perl6 file.pl" but get error "Undeclared name: Thread used ..." Any ideas how to fix the problem? (The document doesn't mention using any packages.)
Multiple condition IF statement using grep and eq
1 direct reply — Read more / Contribute
by Anonymous Monk
on May 04, 2016 at 12:53

    I have a IF statement in this form:

    if (grep $_ == $F[1],73,89,121,101,117,69,77,67,115,81,97,65,113) {

    That compares values held within $F1 to those listed. I wish to add an additional condition that checks another variable other than $F1 but i'm struggling somewhat with the syntax and how this will work with the grep. For example:

    if (grep $_ == $F[1],73,89,121,101,117,69,77,67,115,81,97,65,113 && $inext eq "Global.SAM")

    Each condition works individually, but the latter condition testing $inext is ignored when written in this form. Why is this happening and what could be a solution to the problem?

Cleaning up cpantesters
1 direct reply — Read more / Contribute
on May 04, 2016 at 11:53

    This isn't really the best place to ask this, but I've submitted this to various contact addresses on cpantesters over the past year or so, and never received an answer, so I'll ask here in the hopes that someone can answer.

    Over the years, I've contributed a number of modules to CPAN that needed to be renamed. In 2007, I renamed a bunch to fit the accepted naming standards such as:

       DateManip renamed to Date-Manip

    and I've renamed a couple based on recommendations from the perl-module list, or for various other reasons such as:

       Locale-Messages renamed to Locale-VersionedMessages
       cpantorpm renamed to App-CPANtoRPM

    Unfortunately, if you go to my cpantesters.org page, all of the old distribution names appear in the "Distribution Summary" box. Is there anything that I can do to clean up whatever data is used to create that list? I'd like to have the list reflect only modules that currently exist if possible?

One-on-one Perl tutorial
7 direct replies — Read more / Contribute
by dominick_t
on May 04, 2016 at 10:43
    Hello-- I've recently posted a specific question and received some much appreciated input towards a solution. I am interested in learning more about Perl & regular expressions, and I'd really benefit from having some one-on-one lessons in person. I live in New York City. Any suggestions as to how to find someone in the area who could offer, say, a few hours of instruction one day? Open to bartering arrangements or doing it the old-fashioned way (cash). Thanks very much in advance.
FTP or scp or SFTP from Windows to server
1 direct reply — Read more / Contribute
by ravi45722
on May 04, 2016 at 09:32

    I am trying to get a file from windows to Linux. But my script has to run in Linux. I am Trying Net::SSH File::Remote but not succeed. Any modules to do this?? thanks in Advance

To organize pipe right way.
2 direct replies — Read more / Contribute
by nikolay
on May 04, 2016 at 03:50

    Hi, the great!

    I got a problem w/ the pipes that is concluded in necessity to repeat data, sent into pipe in order to achieve the desired action.

    In my script i have two parts -- a parent and a child. A parent sends signals to pipe, that are recieved by a process, run by the child -- i.e. pipe is used not between the parent and child, but between parent and another process, that the child creates (the process is the mplayer2).

    So, when the parent sends signals (the key pressed by a user) to pipe (to the mplayer2), the mplayer2 not always receives it -- so that the users has to repeat h(is/er) pressings. -- And this is the problem that i want to solve -- to remove the repeatings.

    Here is the code (relevant pieces only).

    use POSIX qw( mkfifo ); mkfifo( $svitok_truby, 0700 ) || die '&#1054;&#1096;&#1080;&#1073;&#10 +82;&#1072; &#1089;&#1086;&#1079;&#1076;&#1072;&#1085;&#1080;&#1103; & +#1090;&#1088;&#1091;&#1073;&#1099; '.$svitok_truby.' : '.$!; if( $nomer_vosproizvodyshchego_protsessu=fork ){ # forces a flush right away and after every write or print on the +currently selected output channel. $|=1; system( '/bin/echo \'seek -10\' >'.$svitok_truby ); }else{ system( '/usr/bin/mplayer -slave -input file='.$svitok_truby.' /tm +p/1.flac' ); }

    Thank you for help!

converting perl to machine language
4 direct replies — Read more / Contribute
by Ganesh Bharadwaj1
on May 04, 2016 at 03:29
    Hi Monks, I want to pass some perl scripts I have created to other colleagues. I dont want them to see what is written inside, since there are some confidential information. I want to know how I can convert the perl scripts to machine language. So, that they can execute the perl script as normal without actually being able to read what is written inside. Any help would be appreciated. Do I write something in shell to convert the perl to machine language? thanks, regards, Ganesh.
regex to capture an unsigned decimal value, but also preserving the user's formatting.
1 direct reply — Read more / Contribute
by darisler
on May 04, 2016 at 00:35
    Hello kind Monks,

    I am trying code a regular expression which will capture an "unsigned fixed decimal" value, preserving the original formatting. Here is what I'm trying to do:

    my $decimal = qr(\d*\.?\d+); $_ = "0.12"; if ( m{(?<value> $decimal)}x ) { say "$_ $+{value}"; } $_ = ".12"; if ( m{(?<value> $decimal)}x ) { say "$_ $+{value}"; } $_ = "12."; if ( m{(?<value> $decimal)}x ) { say "$_ $+{value}"; } $_ = "12"; if ( m{(?<value> $decimal)}x ) { say "$_ $+{value}"; }
    When I run this I get the following:
    0.12 0.12 .12 .12 12. 12 12 12

    But the third line, I am not preserving the trailing decimal place, although the values should be equal.

    Can anyone point out how I could change my "qr" so that it "works" for the third line?

Add your question
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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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.