Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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
Perl reference array
4 direct replies — Read more / Contribute
by teun-arno
on Mar 28, 2015 at 16:57
    I have a question about the following :
    use Data::Dumper; # it seems that ', ,' in the third record is not producing a index in +the array. $arr= [ [1,2,3,4,5,6,7,8,9 ], #works as expected [1,2,3,'',5,6,7,'',9 ], #works as expected [1,2,3, ,5,6,7, ,9 ], #does not work as expected "empty fields " + are ignored ]; my $dd=Data::Dumper->new([$arr],[ qw(arr) ] )->Indent(1)->Quotekeys(0) +->Dump; print $dd; $str_arr=q`$arr= [ [1,2,3,4,5,6,7,8,9 ], [1,2,3,'',5,6,7,'',9 ], [1,2,3, ,5,6,7, ,9 ], ];` ; print "\n\n"; print $str_arr ; $str_arr=~ s/,\s*,/,'',/g; # filling in the empty fields print $str_arr ; $arr = undef; $arr = eval $str_arr; my $dd=Data::Dumper->new([$arr],[ qw(arr) ] )->Indent(1)->Quotekeys(0) +->Dump; print $dd; # this seems to work, next question is : The original $arr is send to +a subroutine. # How to stringify that in the subroutine without hardcoding this. ( a +s I have done in the above ) ! #
    Thanks for your time dear perl monks.
Archive::Tar is working with perl-5.8.7 but giving Out Of Memory error with perl-5.20.1
2 direct replies — Read more / Contribute
by Sushant_K
on Mar 28, 2015 at 14:44
    Hello Monk, I am facing an issue with Archive::Tar module(version 1.96). I am trying to use 'Archive::Tar->new()' on one tar.gz file the compressed size of which is 31 MB and if extracted size is 151 MB. I have written a sample small program for this. It works well with perl version 5.8.7 however for perl version 5.20.1 it gives out of memory error. Following is my program-
    use Archive::Tar; my $bundle = "C:\\My_Sample.tar.gz"; my $tar_engine = Archive::Tar->new($bundle, 1); if($tar_engine == undef) { print "\nCant get tar object\n"; } else { my @filelist = $tar_engine->list_files(); if(!$tar_engine->extract(@filelist)) { my $ret = 1; print "\nError in extraction.\n"; } } print "\nCompleted Successfully\n";
    For perl-5.20.1, it gives out of memory error when Archive::Tar->new() is called. I am trying this out on Windows. Can anyone help me out ? Please let me know you require any more information.
Character in 'b' format wrapped in unpack
3 direct replies — Read more / Contribute
by BrowserUk
on Mar 28, 2015 at 11:14

    What does the error message mean?

    $x = "\x55\xAA\x55\xAA";; substr( $x, $_, 1 ) = chr( ord( substr( $x, $_, 1 )) << 1 ) for 0 .. 3 +; print unpack 'b*', $x;; Character in 'b' format wrapped in unpack at (eval 34) line 1, <STDIN> + line 26. Character in 'b' format wrapped in unpack at (eval 34) line 1, <STDIN> + line 26. 01010101001010100101010100101010

    Note: The error comes from the unpack line, not the cobbled together bit-string shift left.

    Did the shifting manage to create a wide character?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
beginner's question regarding objects
3 direct replies — Read more / Contribute
by McSvenster
on Mar 28, 2015 at 08:16

    Dearest wise monks

    I am just starting with oo perl, read your excellent introductions on referencing, but still there's not enough light coming out of my brain :-)

    I am populating an object with the attributes 'head', 'opinion', 'result' like this:

    my $item = Item->new("something","another thing","the essence");

    When I dump the object (with Data::Dumper) I get:

    $VAR1 = bless( { 'head' => 'something', 'opinion' => 'another thing', 'result' => 'the essence' }, 'Item' );

    How can I get the whole contents of $item (all between the curly brackets)? I know how to get the single elements... but not the whole object.

    The aim is to index it with elasticsearch:

    $e->index( index => $index, type => $type, id => $id, body => { head => $head, opinion => $opinion, result => $result, } );

    and I want to replace the "body" with my item

    Thanks a lot in advance for any enlightenment!

    MCS
Installing modules in Windows (Strawberry Perl) without administrator privileges
4 direct replies — Read more / Contribute
by hda
on Mar 28, 2015 at 03:58
    Wise monks,

    I have recently started working in a very conservative organization where people are not allowed to install things in their computers beyond what is deemed strictly necessary, which is sort of a curse for this long time Perl adept ;-) I am also a long time Linux user, so I am completely unfamiliar with the current Windows environment at $work. I could install Strawberry Perl thanks to the zipped package. However, I could not figure out how to install additional modules. The problem seems to stem from a permission problem, as CPAN fails to connect to the internet. I had the same problem downloading R packages, but I circumvented this by getting the individual .zip files and allowing R know where they are. I am wondering if there is a similar procedure I can implement with Strawberry Perl in this particular setting. Any hint will be appreciated!

    Thanks to all you, wise and gentle monks!

    hda
perl code not working after moved new host with latest perl version
5 direct replies — Read more / Contribute
by dpprabhuindia
on Mar 28, 2015 at 03:12

    I am new to perl, I am facing issue with perl script which does job to get data from command 'rrdtool fetch' to html output with graphs. Now it gives error as Uninitialized value, but same perl script os working on other host which has old perl version. This working perl version on RHEL5 machine

    perl -v This is perl, v5.8.8 built for i386-linux-thread-multi
    and This perl version on RHEL6 which is not working

    #!/usr/bin/perl if ($ENV{'REQUEST_METHOD'} eq "POST") read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } elsif ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; } else { exit 1; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/^//g; $list{$name} = $value; } $url = "/aisin/cgi-bin/chkts.pl"; $end = time(); $begin = $end - ($list{period} ? $list{period} : 3456000); $dir = "/home/nagios/var/rrd/ts/$list{sid}"; $lin = $list{top}; opendir(DIR, $dir) || die("can't open directory $dir"); @files = grep(/.+\.rrd$/, readdir(DIR)); closedir(DIR); foreach $f (@files) { next if ( ($list{exceptundo} eq 'on' && $f =~ /UNDO/) || $f =~ /^dbd +ata/ ); next if ( ($list{excepttemp} eq 'on' && $f =~ /TEMP/) || $f =~ /^dbd +ata/ ); open(RRD, "rrdtool fetch $dir/$f AVERAGE -s $begin -e $end|") || next +; @f = (); $i = 0; while (<RRD>) { next if ((!/:/) || /nan +nan +nan/); @f = split; next if ($f[3] == 0); if ($i < 1) { $lsiz1 = $f[1]; $rfre1 = $f[2]; $rsiz1 = $f[3]; } else { $lsiz2 = $f[1]; $rfre2 = $f[2]; $rsiz2 = $f[3]; } $i++; } close(RRD); $count = @f; next if ($count == 0); $b = $f; $b =~ s/(.*)\.rrd/\1/; #printf "%s %.0f %.0f %.0f %.0f %.0f %.0f<br/>\n", $b, $lsiz1, $rfre1 +, $rsiz1, $lsiz2, $rfre2, $rsiz2; $amount{$b} = $lsiz2 - $lsiz1; $ratio{$b} = $amount{$b} / $rsiz2; } print "Content-type: text/html\n\n"; print "<html>\n"; print "<body>\n"; print "<center>\n"; print "<p>\n"; print "<H3>\n"; if ($list{period} <= 86400) { printf "last %d hours growth\n", $list{period} / 3600; } else { printf "last %d days growth\n", $list{period} / 86400; } print "</H3>\n"; print "<table border=1>\n"; printf "<tr><th>top %d amount<th>Mega<th>%%<th>top %d utilization<th>M +ega<th>%%\n", $lin, $lin; $i = 0; foreach $k (sort {$amount{$b}<=>$amount{$a}} (grep {$amount{$_}==$amou +nt{$_}} (keys %amount))) { #foreach $k (sort {$amount{$b}<=>$amount{$a}} (keys %amount)) { $k1[$i] = $k; $a1[$i] = $amount{$k}; $r1[$i] = $ratio{$k}; #printf "<tr><td>%s<td>%.2f\n", $k, $amount{$k} / 1024 / 1024 ; last if (++$i == $lin); } $i = 0; foreach $k (sort {$ratio{$b}<=>$ratio{$a}} (grep {$ratio{$_}==$ratio{$ +_}} (keys %ratio))) { #foreach $k (sort {$ratio{$b}<=>$ratio{$a}} (keys %ratio)) { $k2[$i] = $k; $a2[$i] = $amount{$k}; $r2[$i] = $ratio{$k}; #printf "<tr><td>%s<td>%.2f\n",$k, $ratio{$k} * 100; last if (++$i == $lin); } for ($i = 0; $i < $lin; $i++) { printf "<tr>\n"; printf "<td><a href=%s?sid=%s&period=%d&ts=%s>%s</a>", $url,$list{sid},$list{period},$k1[$i],$k1[$i]; printf "<td align=right>%.2f<td align=right>%.2f", $a1[$i] / 1024 / 1024, $r1[$i] * 100; printf "<td><a href=%s?sid=%s&period=%d&ts=%s>%s</a>", $url,$list{sid},$list{period},$k2[$i],$k2[$i]; printf "<td align=right>%.2f<td align=right>%.2f\n", $a2[$i] / 1024 / 1024, $r2[$i] * 100; } print "</table>\n"; print "</center>\n"; print "</body>\n"; print "</html>\n";

    pls help me to fix this issue with latest perl version machine. Thanks in advance for your help. dpprabhuindia

Perl Functions
5 direct replies — Read more / Contribute
by bmcquill
on Mar 27, 2015 at 23:48
    I doing a Perl tutorial and I have a problem posed: Create a library with a function that takes in an array of numbers (of arbitrary size). The function will then calculate the average of the numbers, the total of all of the numbers added together, and a new array of numbers which is comprised of the original input numbers each divided by 2. It will then return a new list with all of that information. What I'm stuck on is how to write a script that creates the array and pass that to the library, completing the steps above. Anyone have similar examples?
Perl's bad at arithmetic?
2 direct replies — Read more / Contribute
by BrowserUk
on Mar 27, 2015 at 19:03

    Can anyone explain these outputs:

    print +( 1<<(2**$_+$_-1) )-1 for 4,5,6;; 524287 68719476735 31 print unpack 'b*', pack 'Q', ( 1<<(2**$_+$_-1) )-1 for 4,5,6;; 1111111111111111111000000000000000000000000000000000000000000000 1111111111111111111111111111111111110000000000000000000000000000 1111100000000000000000000000000000000000000000000000000000000000

    What I am expecting:

    1. 2^4 + 4 - 1 = 19
      1111111111111111111000000000000000000000000000000000000000000000
    2. 2^5 + 5 - 1 = 36
      1111111111111111111111111111111111110000000000000000000000000000
    3. 2^6 + 6 - 1 = 69
      1111111111111111111111111111111111111111111111111111111111111111

    I know it can't be Perl's fault? But there it is...


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
perl parallel script
2 direct replies — Read more / Contribute
by amagana
on Mar 27, 2015 at 18:41
    I ran this script "parallel_passwd.pl" from a linux box and I wanted to change my password on a solaris 10 server but after I enter the old password and new password I get nothing back, not even a timeout or error. I run the perl script like this: perl ./parallel_passwd.pl -l mylogin remoteserver https://github.com/salva/p5-Net-OpenSSH-Parallel/blob/master/sample/parallel_passwd.pl
Perl Strict 502 Error No DEBUG SUPPORT
6 direct replies — Read more / Contribute
by ninjazin
on Mar 27, 2015 at 15:48
    Hello, I'm using strict and warnings in the perl program , However strict getting included without any errors but it doesn't helping with debugging at all. Here what i'm testing,
    #!/usr/bin/perl use strict; use warnings; use CGI; my $test = new CGI; print $test->header("text/html"); $test->start_html("Perl Test") print $test->h1("Perl is working!"); print $test->end_html;
    As this script has syntax error i expected some kind of error as output as i'm using strict and warnings, but instead of it is showing 502 error at server no matter what's the error.

    Here what it shows , http://postimg.org/image/5ksy74oil/

    I have searched a lot about solution and failed. so i had no choice but asking in community. Any help will be highly appreciated.

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
  • 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?
    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 about the Monastery: (8)
    As of 2015-03-29 17:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When putting a smiley right before a closing parenthesis, do you:









      Results (631 votes), past polls