Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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
-e line 1
3 direct replies — Read more / Contribute
by Ignoramus1
on May 28, 2015 at 19:44
    Working on Windows 8 x64 system and continue to run into multiple errors. Copy of command prompt commands and errors listed bellow. Any help would be greatly appreciated.

    C:\Desktop\MSP Project Working Folder\MSP-forward>perl tagcl -minlen 100 -nomatch 3 -verbose -64 -trim_within 100 -log -fastq msp898 3_F09R08.fastq -out tagcleaner_out/msp8983_F09R08_4M2_SWS6.15F -tag5 ACGCTCGACAA AAGCACATTTAATTCATTATCC -tag3 ATGAGTTTCTGGGGTGCTACTACAGTGCT

    Can't find string terminator "'" anywhere before EOF at -e line 1.

    ERROR: input file for -fastq is in UNKNOWN format not in FASTQ format. Try 'perl -h' for more information. Exit program.

    ERROR: Can't open file : No such file or directory

    C:\Desktop\MSP Project Working Folder\MSP-forward>perl -e ta -minlen 100 -nomatch 3 -verbose -64 -trim_within 100 -log -fastq msp 8983_F09R08.fastq -out tagcleaner_out/msp8983_F09R08_4M2_SWS6.15F -tag5 ACGCTCGA CAAAAGCACATTTAATTCATTATCC -tag3 ATGAGTTTCTGGGGTGCTACTACAGTGCT

    Can't locate in @INC (@INC contains:

    C:/Strawberry/perl/site/lib C:/Str awberry/perl/vendor/lib C:/Strawberry/perl/lib .). BEGIN failed--compilation aborted.

    C:\Desktop\MSP Project Working Folder\MSP-forward>perl -e "t -minlen 100 -nomatch 3 -verbose -64 -trim_within 100 -log -fastq ms p8983_F09R08.fastq -out tagcleaner_out/msp8983_F09R08_4M2_SWS6.15F -tag5 ACGCTCG ACAAAAGCACATTTAATTCATTATCC -tag3 ATGAGTTTCTGGGGTGCTACTACAGTGCT"

    Number found where operator expected at -e line 1, near "minlen 100" (Do you need to predeclare minlen?)

    Number found where operator expected at -e line 1, near "nomatch 3" (Do you need to predeclare nomatch?)

    Number found where operator expected at -e line 1, near "trim_within 100" (Do you need to predeclare trim_within?)

    syntax error at -e line 1, near "minlen 100"

    Search pattern not terminated at -e line 1.

system stdout redirected ok to a file but not to a variable.
4 direct replies — Read more / Contribute
by guybrush
on May 28, 2015 at 16:56

    Hi, I'm trying to run a command on a unix box using system because I need the exit code. but I also need the stdout and stderr. so I try some STDOUT redirection unfortunatelly it works if I redirect to a file:

    open(STDOUT, '>' ,"kk.txt" ) or die "Can't redirect stdout: $!";

    But not when I do it to a variable:

    open(STDOUT, '>' ,\$output ) or die "Can't redirect stdout: $!";

    This is my Testing code:

    #!/usr/bin/perl my $exitcode ; my $output=''; my $error=''; # take copies of the file descriptors open(OLDOUT, ">&STDOUT"); open(OLDERR, ">&STDERR"); #close current outs as per manual of open close(STDOUT) or die "Can't close STDOUT: $!"; close(STDERR) or die "Can't close STDERR: $!"; # redirect stdout and stderr open(STDOUT, '>' ,\$output ) or die "Can't redirect stdout: $!"; #open(STDOUT, '>' ,"kk.txt" ) or die "Can't redirect stdout: $!"; open(STDERR, '>' ,\$error ) or die "Can't redirect stderr: +$!"; printf "Before system\n"; # run the program system("echo I cant get this into a variable"); $exitcode=($? >>8); printf "After System\n"; # close the redirected filehandles close(STDOUT) or die "Can't close STDOUT: $!"; close(STDERR) or die "Can't close STDERR: $!"; # restore stdout and stderr open(STDOUT, ">&OLDOUT") or die "Can't restore stdout: $!"; open(STDERR, ">&OLDERR") or die "Can't restore stderr: $!"; # avoid leaks by closing the independent copies close(OLDOUT) or die "Can't close OLDOUT: $!"; close(OLDERR) or die "Can't close OLDERR: $!"; printf "Exitcode: %d\n" ,($exitcode); printf "still here\n"; print $output ; print $error ;

    Please any help on why it does not work the redirection when is a variable?

    Also if posible. how can I do this without system. remember I need exitcode stdout and stderr and I do not want to do any alter to the actual command to do unix redirections.

    Many many thanks.


Moving files recursively to new subfolder
2 direct replies — Read more / Contribute
by jayu_rao
on May 28, 2015 at 14:20
    Hi Monks,

    I am trying to move files / folders in a particular directory to a new subfolder within it using perl script.

    It works for Linux but not in AIX. The same command works on command line without any errors but gives error when run via perl script. Any suggestions on what could be wrong?

    $ nl 1 #!/usr/bin/perl -w 2 use File::Find; 3 sub my_move_log_files { 4 # Get Directory names for moving files; 5 my @log_dirs_to_move = @_; 6 my $src_dir; foreach $src_dir (@log_dirs_to_move) { my $move_cur_logs_cmd="cd $src_dir; mkdir -p $ +src_dir/logs_dir\$(date +%Y%m%d%H%M%S); mv \`/bin/ls -A | grep -v log +s_dir\` \$_"; print "$move_cur_logs_cmd \n"; system("$move_cur_logs_cmd"); } 7 return 1; 8 } 9 my @found; 10 sub findstuff { 11 my $file = $_; 12 return unless -f $file; 13 my $fullpath = $File::Find::name; 14 push @found, $fullpath; 15 } 16 my $dir_to_search = "/home/user1/test"; 17 find(\&findstuff, $dir_to_search); 18 print "Before move: "; 19 print "@found\n"; 20 my $result=my_move_log_files($dir_to_search); 21 find(\&findstuff, $dir_to_search); 22 print "After move: "; 23 print "@found\n"; 24 print "Sample Run: \n"; 25 print "----------------\n" $ perl Before move: /home/user1/test/a.txt /home/user1/test/aa.txt /home/user +1/test/aaa.txt /home/user1/test/aaaa.txt cd /home/user1/test; mkdir -p /home/user1/test/logs_dir$(date +%Y%m%d% +H%M%S); mv `/bin/ls -A | grep -v logs_dir` $_ Usage: mv [-I] [ -d | -e] [-i | -f] [-E{force|ignore|warn}] [--] src t +arget or: mv [-I] [-d | -e] [-i | -f] [-E{force|ignore|warn}] [--] src1 . +.. srcN directory After move: /home/user1/test/a.txt /home/user1/test/aa.txt /home/user1 +/test/aaa.txt /home/user1/test/aaaa.txt /home/user1/test/a.txt /home/ +user1/test/aa.txt /home/user1/test/aaa.txt /home/user1/test/aaaa.txt $ $ $ ls -l ../test/ total 0 -rw-r--r-- 1 user1 user1 0 May 28 02:10 a.txt -rw-r--r-- 1 user1 user1 0 May 28 02:10 aa.txt -rw-r--r-- 1 user1 user1 0 May 28 02:10 aaa.txt -rw-r--r-- 1 user1 user1 0 May 28 02:10 aaaa.txt drwxr-xr-x 2 user1 user1 256 May 28 18:47 logs_dir20150528 +184713 $ $ cd /home/user1/test; mkdir -p /home/user1/test/logs_dir$(date +%Y%m% +d%H%M%S); mv `/bin/ls -A | grep -v logs_dir` $_ $pwd /home/user1/test $ $ ls -ltr total 0 drwxr-xr-x 2 user1 user1 256 May 28 18:47 logs_dir20150528 +184713 drwxr-xr-x 2 user1 user1 256 May 28 18:53 logs_dir20150528 +185347 $ ls -l logs_dir20150528185347 total 0 -rw-r--r-- 1 user1 user1 0 May 28 02:10 a.txt -rw-r--r-- 1 user1 user1 0 May 28 02:10 aa.txt -rw-r--r-- 1 user1 user1 0 May 28 02:10 aaa.txt -rw-r--r-- 1 user1 user1 0 May 28 02:10 aaaa.txt $
How to extract text between two tags?
3 direct replies — Read more / Contribute
by Cursed Chico
on May 28, 2015 at 14:18
    Hello. You can see the html page here, it was pasted there. It starts with <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> OTher writings are Russian but html text is in English. I need to extract the text after the line

    Paper ID - Title (# Reviewers)


    Select Reviewer(s):

    I did this use strict; use warnings; use English qw(-no_match_vars); use Carp; use HTML::TreeBuilder; my $f = 'index.html'; my $tree = HTML::TreeBuilder->new; $tree->parse_file($f); my @options = $tree->find('OPTION'); foreach (@options){ print $_->as_text,"\n"; } $tree->delete; #clear memory sleep(131); but it only parses all text. I want only specific text. Please help me.
WebService::Plotly dies with HTTP::Response=HASH(...)
No replies — Read more | Post response
by docdurdee
on May 28, 2015 at 14:12
    Dearest Monks, I'm trying to use the WebService::Plotly module. It works great on two computers (running p5.20.1 on OS X 10.10.3), but it dies without warnings on three other computers (running p5.20.1 on OS X 10.8.4) dumping: HTTP::Response=HASH(0x7f87ba65afe0) Do you have any suggestions as to how to solve this problem? Here is the code:
    use Modern::Perl; use WebService::Plotly; my $plotly = WebService::Plotly->new( un => $user, key => $key); my @ss = map {[split]}( '2.1120 0.0047', '2.1160 0.0045', '2.1200 0.0058', '2.1240 0.0045', '2.1280 0.0036', '2.1320 0.0029', '2.1360 0.0024', '2.1400 0.0032', '2.1440 0.0020', '2.1480 0.0014', ); my @ds = map{$_->[0]} @ss; my @ps = map{$_->[1]} @ss; my $response = $plotly->plot( \@ds, \@ps ); print "url is: $response->{url} \n"; print "filename on our server is: $response->{filename} \n";
    For the computers that it works, I can dump $response:
    $VAR1 = { 'filename' => 'plot from API (7)', 'warning' => '', 'url' => '', 'message' => '', 'error' => '' };
    Thanks! D
How can I import text to Access
2 direct replies — Read more / Contribute
by Broggy69
on May 28, 2015 at 13:12
    I have programmed in VB.Net and trying to learn PERL. I have read vari +ous methods searching with google, but none work. If it helps below i +s the code I would like to convert to PERL if possible. Dim sCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" Dim conp As String = "SELECT * INTO [Input] FROM [Text;DATABAS +E=" Dim WF As String = "W:\Glenn-123456\Test\" Dim Conn_1 As New OleDbConnection(sCon & WF & "\VDD\Data\DevCo +mm1.mdb") Dim Comm_1 As New OleDbCommand(conp & WF & "\VDD\Data\;HDR=No] +.[DevComm1.txt]", Conn_1) Dim dSysDate As String = "" Conn_1.Open() Comm_1.ExecuteNonQuery() Conn_1.Close()
Using SSH and SCP in a perl script with taint flag
2 direct replies — Read more / Contribute
by stefl
on May 28, 2015 at 10:38

    Hi wise monks, after several days of going in circles I would like some help.
    I have a webform (CGI) that I am developing, and after the user fills in various parts of the form, I need to copy a file from one server to another. I have a short sample code (that isn't CGI-based but may illustrate my problem) below:

    #!/usr/bin/perl -w -T use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => "<IP>", user => "<username>", raw_pty => 1 ); $ssh->run_ssh() or die "SSH Process couldn't start: $!"; $ssh->exec("stty raw -echo"); my $who = $ssh->exec("whoami"); print ($who); my $scp = "scp <file> <username>\@<IP Address>:<destinationpath>; $ssh->exec($scp) or die "SCP Process error: $!";

    I understand that the taint flag isn't necessary in this short example, but it is required for the main application and I believe is causing most of my problems.
    Prior to this attempt, I have also tried using system() to run the scp:

    system('ssh <user>\@<IP> scp $file <user2>\@<Destination IP>:<destinat +ion path>');

    This involved untainting all variables before this call. This attempt resulted in a slew of errors ("Can't exec 'ssh': No such file or directory", "sh: 1: ssh: not found").
    I had read (although I may be wrong) that the Net::SSH::Expect module does not have full support for taint mode.
    Also, as the script is generally being run from the web, the user for the commands is www-data (I don't know exactly what relevance this has, but it seems to be important, at least in my debugging attempts).
    Thank you very much for any help or advice you can give. If more information is needed, I'm happy to provide it (I just can't think of anything else to include at the moment). Cheers!

How to deploy new Perl Modules to other machines?
2 direct replies — Read more / Contribute
by mahesh557
on May 28, 2015 at 10:17
    Hi, I have some perl code which uses some additional perl modules. I have deployed the code along with perl folder to other machines so that it can be used on their machines. Now i have updated my perl code which required additional perl modules (XML::Feed). I have downloaded the additional modules manually on my machine using ppm. Now i have problem deploying the additional modules which are downloaded by ppm to other machines. Any idea how i can work it out?
[C Question] Determine if gcc provides erfl() function
3 direct replies — Read more / Contribute
by syphilis
on May 28, 2015 at 09:22
    I have a module that assumes that the compiler provides the erfl() function.
    The assumption is obviously wrong.
    What's the best way of determining, during the 'perl Makefile.PL' stage of the build, whether the compiler does, in fact, provide the erfl() function ?

    The cpan-tester FAIL reports that I'm receiving en-masse wrt BSD systems all seem to relate to gcc compilers. (I don't think there's a FAIL report there for anything other than BSD && gcc.)
    Therefore, I'm quite happy (for the moment, anyway) to limit this question/discussion to gcc compilers only.

DBD::CSV Update
3 direct replies — Read more / Contribute
by PERL_fresher
on May 28, 2015 at 05:46

    Hello Fellow monks I need some help with the update of one of the CSV files that Im trying to do. Basically one of the file has set of records which I dont want to update for example

    Souce Data X~Y~Z 1~2~3 col1~col2~col3~col4~col5 A~B~C~D~E
    Above is the file format. what i need to do is to start updating this table from row 3 where the actual data is

    my $dbh = DBI->connect("dbi:CSV:",undef,undef,{ f_dir => $_ENV::TempFilesDIR, csv_sep_char => "~", csv_quote_space => 0}) or die $DBI::errst +r; $dbh->{'csv_tables'}->{'cimp_money'} = { 'file' => 'Aviva_cimp_ +money_positive.txt', col_names => [qw(rcrd_typ +e seq_no emp_no forename surname initial ni_no ttl gender dob emp_cnt +rbtn emplyr_ctr tax_peri +od tax_yr exch_amt)] $dbh->do('UPDATE cimp_money SET forename=?,surname=? WHERE emp_no=?',u +ndef,$wrk_forename,$wrk_surname,$wrk_emp_no) or die $DBI::errstr;

    Basically updates are happening correctly but the issue Im facing is since the header records i.e. first 2 lines are just 3 columns and details records has 4 columns its assuming that even in first 2 rows also it has a header and its updating ~ to row 1 and 2 which is what I want to remove now

    Output Data X~Y~Z~~ 1~2~3~~ col1~col2~col3~col4~col5 A~B~C~D~E

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (7)
    As of 2015-05-29 04:24 GMT
    Find Nodes?
      Voting Booth?

      In my home, the TV remote control is ...

      Results (574 votes), past polls