Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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
write to Disk instead of RAM without using modules
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 21, 2016 at 07:04
    I am trying to compare multiple files simultaneously for similar pattern search. I have multiple files with each file of size 500MB approximately. I have written a script which works well when I run with some of my files but when I increase the number of files, script hangs. I think it is due to memory limitation. Is there any other way of storing hash in Disk rather than RAM without using any of perl module.
First word
2 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 21, 2016 at 07:00

    I would like to get the first word from each row of my @AoA[][] and push it into the array @kmers. Can anybody help me get there? This is what I've done so far. Thanks in advance everybody!

    my(@kmers); my($x) = 0; my($y) = 0; for ($x=0, $x<7, $x++){ for ($y=0, $y<$AoA[$x], $y++){ my($firstword) = ''; $firstword = $AoA[$x][$y] =~ /^(\w+)/; push @kmers, $firstword; print $firstword."\n"; } }
Filter array of hashes for specific keys
2 direct replies — Read more / Contribute
by ddominnik
on Oct 21, 2016 at 05:35

    Say I have an array of hashes like this:

    @response = [ { 'name' => 'foo', 'id' => 'bar', 'self' => 'baz' }, { 'name' => 'foo2', 'id' => 'bar2', 'self' => 'baz2' }, ]

    Now I have a subroutine called filter which I call like this:

    my $responseref = \@response; my $filtered_response = filter ($responseref, 'name', 'id');

    How would the subroutine need to look to get an array reference as return value of which the array would look like:

    @response = [ { 'name' => 'foo', 'id' => 'bar', }, { 'name' => 'foo2', 'id' => 'bar2', }, ]

    Ideally it should work without installing any additional modules
    It should also be pretty generic, it should for example be able take a different amount of fields to filter through every time

crawl a full webpage one time
2 direct replies — Read more / Contribute
by liuweichuan
on Oct 21, 2016 at 03:56

    using Perl, how to get a full web page (include ajax web) once like phantomjs ? And what kind of brower useragent can do this?

Batch FIle Operations
4 direct replies — Read more / Contribute
by ankit.tayal560
on Oct 21, 2016 at 01:29

    Hi Monks, This is not a query related to some specific code/script but in a general scenario. suppose if I am having a script in which I have defined several (3-5) paths. I want to run this script through a batch file so I make a batch file.

    perl @pause

    Now if I want to pass the paths required through batch file only what should I do how can I pass paths through batch file directly into my script. any help or suggestions is appreciated.

    Thanks in advance

Attempt to reload LWP/Protocol/
2 direct replies — Read more / Contribute
by UMonk
on Oct 20, 2016 at 16:20
    Hi Monks,
    Am trying to hit a https - Vendor site using our proxy and trying to download a xls file, the scripting instructions are given by the Vendor themselves. Unfortunately am facing Error GETing : https://xxxxx :Attempt to reload LWP/Protocol/
    I have the old version of perl installed in the machine where it is missing some modules, so I have extracted the latest in a folder along with necessary modules and created a dummy env file which am sourcing before running the script.
    use strict; use File::Basename; use Getopt::Long; use WWW::Mechanize; use URI qw( ); my $thisScript = basename($0); print "==START $thisScript==\n"; my ($help, $proxy, $username, $password); my $urlsToBeDownloaded = "file-url-list.txt"; my $url = "https:xxxxxxxxxxxxx"; usage() if (@ARGV < 2 or ! GetOptions('proxy:s' => \$proxy, 'username=s' => \$username, 'password=s' => \$password) or defined $help); if ($username eq "" || $password eq "") { usage(); } my $mech = WWW::Mechanize->new(); if($proxy ne ""){ $mech->proxy(['http', 'https'], $proxy); } $mech->get($url);
    Am getting error right at this point I have another team who has implemented this automation successfully. Any knowledge or suggestion will be greatly appreciated.
Testing $! when use strict is in effect
1 direct reply — Read more / Contribute
by Bloehdian
on Oct 20, 2016 at 14:41

    Hi monks,

    probably a quite simple question for most of You, but I've just got stuck on it:

    In one of my progs I have the following

    if ( ! defined $test && $! == EWOULDBLOCK ) {

    which, since use strict is effect gives the error message

    "Bareword "EWOULDBLOCK" not allowed while "strict subs" in use"

    How can I test $! anyways?



sfv checker sting crc32
2 direct replies — Read more / Contribute
by reptizarx3
on Oct 20, 2016 at 12:59

    Hi guys! First of all newbie here, but want to learn, need help about one script sfv checker for crc checking on uploaded files on ftp server(wingftp): My steps: 1.Download and install Stawberry perl x64 run on win7x64, (installed into C:\Strawberry) 2.Restart 3.Download String-CRC32-1.5.tar.gz and unzip it to other partition d: Installation instruc says: "perl Makefile.PL" "make" "make test" "make install" 4.Open Perl cmd and input D:\String-CRC32-1.5\Makefile.PL 5.input make and get this error: 'make' is not recognized as an internal or external command, operable program or batch file. What i doing wrong? Here is the whole script and don't know even i get to work:

    #!/usr/bin/perl # Make sure this points to your perl executable # String::CRC32 is required you can install using cpan use String::CRC32; # Wing Server SFV Checker v1.00b - benny / # # I put this together because the sfv checker that comes with Wing Ser +ver isn't recursive # and wont check sub directories inside the specified sfv checking dir +ectory # # Apologies for the sloppy code I wanted a working sfv checker quick, +ill try and clean it # up and add more features when I have more time. # # Known bugs / Irrelevant issues? # - As of now this will only check files in a sfv against the files u +ploaded # to the directory that your uploading to, so if any file not in th +e sfv is uploaded # it will just be ignored and possible to just have misc unwanted f +iles laying around.. # # - The $home variable could cause issues with multiple domains and u +sers depending on your setup.. # on my setup i have all my files going to /usr/files and my one us +er having a home directory of /usr/files # so everything sent to this script would be /Dircreated/Files.. wh +ich would be # ($home/Dircreated/Files) -> /usr/files/Dircreated/Files # - I'll add a more flexable $home in the future! # # - If there is more than one sfv this script will just exit.. # # Using / Installing this # - You will need to run cpan and install String::CRC32 # - Put this perl script somewhere you can find it later # - chmod +x /path/to/where/you/put/checker # # - Goto the Wing Server http admin panel and click on a domain # - Click on Ftp Events # - Double Click OnFileUploaded # - Check mark "Enable Execute Program" # - Program Path is /path/to/where/you/put/checker you did earlie +r # - For Paramaters put: %Dir # - Press OK! # # Conclusion # - I would recommend having your ftp client set a priority on sendin +g sfv first but on a side # note even if you sent a few files first and then uploaded the sfv + how this scans files apon upload # it will check the previous files you uploaded and add them to the + cached files # # - Enjoy and let me know if you have troubles or like this! # my $home = "/usr/files"; my $sfiles = 0; my $tfiles = 0; # For creating empty missing/bad files sub touch { if ($#_ != 0) { return; } if ( -f $_[0] ) { return; } open tch, ">$_[0]"; close tch; } opendir(SFVCHK, ${home}.$ARGV[0]); my @SFVFIN = grep(/\.sfv/, readdir( +SFVCHK)); closedir(SFVCHK); opendir(SFVCHK, ${home}.$ARGV[0]); my @CMPCHK = grep(/^\[.*COMPLETE\s\ +]$/, readdir(SFVCHK)); closedir(SFVCHK); # If there isn't a sfv or more than 1 just exit if (@SFVFIN != 1) { exit; } # Keep a hidden verified file to prevent double checking and system lo +ad my @CHECKED = (); if ( -e "${home}$ARGV[0]/.chk" ) { open CKSFV, "<${home}$ARGV[0]/.chk"; while (<CKSFV>) { chomp($_); push(@CHECKED, $_); } close CKSFV; } # Open file for appending anymore valid files we might come across open CKSFV, ">>${home}$ARGV[0]/.chk"; # Open the sfv and log the files that are suppose to be here # before we run the sfv checker to compare open SFVFD, "<${home}$ARGV[0]/$SFVFIN[0]"; while (<SFVFD>) { chomp($_ +); push(@LINES, $_); } close SFVFD; foreach my $deldir (@CMPCHK) { rmdir "${home}$ARGV[0]/$deldir"; } foreach my $line (@LINES) { chomp($line); if ($line =~ /^;/) { next; } my @SP = split(/ /, $line); my $rel = uc($SP[1]); $tfiles++; $rel =~ s/(\W)//g; # Make sure the crc string doesnt contain a +ny control characters if ( -e "${home}$ARGV[0]/$SP[0]" ) { my $LFILE = $SP[0]; if (grep(/$LFILE/, @CHECKED)) { $sfiles++; next; } open(CRCK, "${home}$ARGV[0]/$SP[0]"); my $crc = crc32(*CRCK) +; close(CRCK); my $hex = sprintf "%x", $crc; $hex = uc($hex); if (length($hex) < 8) { $hex = "0".$hex; } if (length($rel) < 8) { $rel = "0".$rel; } if ($hex eq $rel) { if ( -e "${home}$ARGV[0]/$SP[0]-missing" ) { unlink("$ +{home}$ARGV[0]/$SP[0]-missing"); } if ( -e "${home}$ARGV[0]/$SP[0]-bad" ) { unlink("${hom +e}$ARGV[0]/$SP[0]-bad"); } print CKSFV "$LFILE\n"; $sfiles++; } else { if ( ! -e "${home}$ARGV[0]/$SP[0]-bad" ) { touch("${ho +me}$ARGV[0]/$SP[0]-bad"); } } } else { if ( -e "${home}$ARGV[0]/$SP[0]-missing" ) { next; } touch("${home}$ARGV[0]/$SP[0]-missing"); } } close CKSFV; my $newdir = sprintf "[ %iF %iF FILES - 0.00%% COMPLETE ]", $sfiles, $ +tfiles; if ($sfiles != 0) { $newdir = sprintf "[ %iF of %iF - %.1f%% COMPLETE +]", $sfiles, $tfiles, (($sfiles / $tfiles) * 100); } if ($sfiles == $tfiles) { $newdir = "[ ${tfiles}F COMPLETE ]"; } mkdir "${home}$ARGV[0]/$newdir";
Reference is experimental
6 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 20, 2016 at 10:16

    Hi, I keep getting the following error message: "shift on reference is experimental at beta_table_maker line 27. Not an ARRAY reference at beta_table_maker line 27, <FILEHANDLE> line 1". How can I solve this? Thanks in advance

    my($counter) = 0; my(@AoA); while (@ARGV){ my($filename) = $ARGV[$counter]; open (FILEHANDLE, $filename); my(@tmp) = <FILEHANDLE>; shift $tmp[0]; push @AoA, [ @tmp ]; close FILEHANDLE; $counter++; } my ($aref) = ''; foreach $aref (@AoA){ print "\t [ @$aref ],\n"; }
Can't locate loadable object for module HTML::Embperl in @INC
2 direct replies — Read more / Contribute
by tushar_linux
on Oct 20, 2016 at 10:07

    Hello Monks,I am new to perlmonks and struggling with my apache webserver.

    The htdocs of apache has ehmtl pages and perl scripts. I am able to launch the webserver with html pages. But getting below error while browsing ehtml pages.

    Thu Oct 20 09:45:37 2016 error Can't locate loadable object for module HTML::Embperl in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /opt/web/cgi-bin/ line 18, referer: Thu Oct 20 09:45:37 2016 error Compilation failed in require at /opt/web/cgi-bin/ line 18., referer: Thu Oct 20 09:45:37 2016 error BEGIN failed--compilation aborted at /opt/web/cgi-bin/ line 18., referer: Thu Oct 20 09:45:37 2016 error Premature end of script headers:, referer:

    It seems my is not able load perl modules.

    Any help would be highly appreciated.thanks in advance

    (edited for formatting by erzuuli)

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.
  • 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 browsing the Monastery: (5)
    As of 2016-10-22 16:45 GMT
    Find Nodes?
      Voting Booth?
      How many different varieties (color, size, etc) of socks do you have in your sock drawer?

      Results (297 votes). Check out past polls.