Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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
SVG getBoundingBox or getWidth and getHeight
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 02, 2015 at 02:59
    Say I have a SVG group, how do I get the width and height? Or the bounding box?
Store log file content from EOF till final occurrence of timestamp
1 direct reply — Read more / Contribute
by jayu_rao
on Jul 02, 2015 at 02:00
    Hi Gurus,

    I have this requirement where I am reading one log file backwards and I have to store the contents into a temporary file with all the lines till a particular timestamp that is derived from another log file. The code that I am using is:

    foreach(@log1_lines){ next unless /initialized/; my ($date, $remaining_line_content) = split /::/,$_,2; $date = Time::Piece->strptime($date, "----- %a %b %d %T %Y"); push @dates, [ $date, $remaining_line_content ]; } my $TIMESTAMP; my $NEW_TIMESTAMP; for (@dates) { $TIMESTAMP = $_->[0]->strftime("%Y-%m-%d %R"); } print "$TIMESTAMP; ... my $log_bckwards = File::ReadBackwards->new($log) or die $!; open my $tmp_log, '+>', $tmp_log_filename or die $!; my @log_final; while (defined(my $log_line = $log_bckwards->readline)) { unshift @log_final, $log_line; last if (($log_line =~ m/$TIMESTAMP:(.*?)$/g)); } print $tmp_log @log_final; close $tmp_log;
    There are 2 challenges that I am facing:

    1. Because I have last if in the while loop, the code stops populating the temporary file as soon as it sees the first occurrence of the HH:MI from the EOF in 2nd log file. I need to have all the lines till the last occurrence of $TIMESTAMP from EOF when reading backwards and not the first occurrence from EOF.

    2. The 2nd log file may not have the exact timestamp (in the seconds field) as in log1 file. So I need to be able to extract all the lines till the Hour:Minute (including all seconds from 60 to 0 OR to the nearest second filed as derived from log1 file)

    Any suggestions?

    Regards,

    Jay

Net::Snmp->session->get_table() data missing
2 direct replies — Read more / Contribute
by sherman
on Jul 01, 2015 at 22:22

    Not sure if anyone raised this before, please point me to the right thread if someone has answer this before.

    I found Net::Snmp->get_table() failed to return all data. Net::Snmp version: 6.0.1.

    I tried to retrieve a nic usagge on a window box but one of interface was not included on get_table() result the debug shows the missing PDU was retrieved from the window box, but not included in the return result object for some reason

    debug: 965 Net::SNMP::PDU::_process_var_bind_list(): { 1.3.6.1.2.1.2.2.1.2.19 => OCTET STRING: Microsoft ISATAP Adapter #4 }

    debug: 1506 Net::SNMP::Message::_process_octet_string(): not translating OCTET STRING, all octets are allowed in a DisplayString

    debug: 965 Net::SNMP::PDU::_process_var_bind_list(): { 1.3.6.1.2.1.2.2.1.2.20 => OCTET STRING: GES EX (Giga Ethernet System) Express PCI Adapter (NDIS) }

    debug: 1506 Net::SNMP::Message::_process_octet_string(): not translating OCTET STRING, all octets are allowed in a DisplayString

    debug: 965 Net::SNMP::PDU::_process_var_bind_list(): { 1.3.6.1.2.1.2.2.1.2.21 => OCTET STRING: Microsoft ISATAP Adapter #5 }

    debug: 1506 Net::SNMP::Message::_process_octet_string(): not translating OCTET STRING, all octets are allowed in a DisplayString

    debug: 965 Net::SNMP::PDU::_process_var_bind_list(): { 1.3.6.1.2.1.2.2.1.2.22 => OCTET STRING: GES EX (Giga Ethernet System) Express PCI Adapter (NDIS) #2 }

    debug: 1506 Net::SNMP::Message::_process_octet_string(): not translating OCTET STRING, all octets are allowed in a DisplayString

    debug: 965 Net::SNMP::PDU::_process_var_bind_list(): { 1.3.6.1.2.1.2.2.1.2.23 => OCTET STRING: Microsoft ISATAP Adapter #6 }

    Data Return by Net::Snmp->session->get_table()

    OID : 1.3.6.1.2.1.2.2.1.2.19, Desc : Microsoft ISATAP Adapter #4

    List : Microsoft ISATAP Adapter #4

    OID : 1.3.6.1.2.1.2.2.1.2.22, Desc : GES EX (Giga Ethernet System) Express PCI Adapter (NDIS) #2 List : GES EX (Giga Ethernet System) Express PCI Adapter (NDIS) #2

    The OID: 1.3.6.1.2.1.2.2.1.2.20 was discarded during the process for some reason

    Does anyone has idea how I get the missing PDU return properly?

    Thanks

    Sherman

Print log at runtime instead of dumping all at once later
5 direct replies — Read more / Contribute
by Technext
on Jul 01, 2015 at 15:17
    I have a Perl script that runs from Jenkins slave. The script executes a shell script kept on remote box A. This shell script actually deploys war on machine A itself. Both machines, Jenkins slave and remote box are CentOS instances.
    use strict; use warnings; use Cwd; use File::Copy; use Getopt::Long; use File::Basename; use Net::OpenSSH; my ($conf_file, $environment, $doexec, $exec, $job, $dest_file, $user, + $host, $IP, $TARGET_SERVER, $JENKINS_JOB, $wrapper, $src_file, $src_ +path, $src_dist_path, $src_full_path, $id_file, $ssh, @array, $line); init(); sub init { $JENKINS_JOB = $ENV{'JOB_NAME'}; $conf_file = "/home/ec2-user/SCM/conf/deploy_build.conf"; open (FH, "<", $conf_file) or die "Cannot open < $conf_file: $!"; while (<FH>) { if ( $_ =~ /\b$JENKINS_JOB\b/ ) { push @array, $_; } else { next; } } foreach $line (@array) { ($job, $src_path, $dest_file, $user, $wrapper) = split(':', $l +ine); $id_file = "/home/ec2-user/.ssh/priv_key"; $ssh = Net::OpenSSH->new($IP, key_path => $id_file, user => $u +ser); $ssh->error and die "Couldn't establish SSH connection: ". $ss +h->error; printf "\n"; if (length $wrapper) { printf "Initiating subroutine for executing wrapper on rem +ote machine...\n"; &exec_wrapper; } else { printf "*** No wrapper specified ****\n"; } } } sub exec_wrapper { my ($stdout, $errput) = $ssh->capture2("~/release/$wrapper"); printf "Output: $stdout\n" if $stdout; die "Error: $errput\n" if $errput; printf "\n\n\n"; }
    Now the issue is that though the program runs fine, it prints output after a while. Whole output is captured in $stdout and then dumped later. Since this job runs as a Jenkins job, the end user has no idea what's going on until the output is dumped. I wanted to print each line as event occurs (runtime) instead of waiting for the whole output to be stored in the variable and dumped later. I did read this article but i'm not sure whether it applies to my case and if it does, how can i implement it. Just to mention, efficiency is *not* a concern in my scenario. Any help will really be appreciated.
Make sin wave with GD
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 01, 2015 at 12:59
    Hi. I using GD package to make wave. But it does not work.
    use GD::Simple;
    $i = GD::Simple->new(400,400);
    ($x1,$y1) = (0,0);
    for ($x2=0; $x2<=400; $x2+=10) {
        $y2 = sin($x2)*400;
        $i->moveTo($x1,$y1);
        $i->lineTo($x2,$y2);
        ($x1,$y1) = ($x2,$y2);
    }
    print $i->png;
    
    How do I get right value for y2? Thank.
Win32::API in perl v5.20.2
5 direct replies — Read more / Contribute
by BillKSmith
on Jul 01, 2015 at 11:43
    I recently upgraded from Active State Perl 5.16.2 to 5.20.2 on my Win7 (64-bit) system. Most went well except for one script (which had been in daily use for a few years. It now fails with the message:
    Can't locate object method "new" via package "Win32::API" at C:\USERS\ +BILL\PERL\ LIB/PDFPrint.pm line 15.

    I have attached the module PDFPrint.pm referenced by the message. The code originally came from a post (http://www.perlmonks.org/?node_id=824842) in this forum

    Notes: In the install procedure, I saved and restored the ppm module configuration with ppm profile save/restore. While attempting to diagnose the problem, I noticed that a newer version of Win32::API was available on ppm. Installing the newer version did not change the result at all.

    Would someone please suggest a way to resolve this issue.

    I also have an unrelated issue with this “upgrade” because ActiveState has removed Perl/Tk from their ppm repository.

    Bill
Testing a .pl script
5 direct replies — Read more / Contribute
by perl_help26
on Jul 01, 2015 at 10:26
    Hello,

    I have a .pl script with the following structure:

    use X; use Data::Dumper; sub func1 {....} sub func2 {....} until (should_stop()) { ..... .... .. }
    I am trying to build a test module for this pl script. Is there a way to export the functions WITHOUT running the while loop? Preferably, I do not want to split the functions into a .pm file. Thanks ...
backtick iterpolation issue
7 direct replies — Read more / Contribute
by idlehands
on Jul 01, 2015 at 08:58

    I'm trying to use backticks to run ls to search for files to gather a list of files that exist. End goal is to parse a group of iTune's playlist files to make sure when import the playlists to itunes it won't drop files if they don't exist. My problem is when I run ls in backticks with the file name, a \r is post pended to the command. making every file show up as not found.

    $playListRow = quotemeta($playListRow); my $lscom = "ls $playListRow 2>&1"; my $result = `$lscom`;

    this outputs: ls: /Volumes/public_files/music/ABC - The Lexicon of Love (1982) {1996 Remaster} V0what.cd/16 Look Of Love (Live).mp3\r: No such file or directory

    No matter how I fiddle with it I can't get the \r to go away. Thanks!

How to extract a sentence?
2 direct replies — Read more / Contribute
by vijayraman
on Jul 01, 2015 at 04:26
    I'm trying to fetch sentences from HTML using HTML::treeBuilder. I could parse upto the div but didnt know how to write the regex for matching a sentence. Can u help me?.Thanks in advance.
how to watch source code debugging with Apache:DB ?
No replies — Read more | Post response
by jjmoka
on Jul 01, 2015 at 04:12
    I'm playing around Apache::DB to remotely debug scripts running under mod_perl-2. I can have an interactive debugging session, but when I finally reach my code there is no way to print symbols or even only a pretty listing of source lines. Did any Monk ever succeed to use effectively Apache::DB inspecting his own vars ?
    http.conf: HTTPD='/usr/sbin/httpd -X -DPERLDB -f ~/debug.d/simple.conf' simple.conf: PerlModule ModPerl::PerlRun <IfDefine PERLDB> PerlRequire ~/handlers/db.pl </IfDefine> <Location /> SetHandler perl-script PerlHandler ModPerl::PerlRun <IfDefine PERLDB> PerlFixupHandler Apache::DB </IfDefine> Options +ExecCGI PerlSendHeader On PerlSetupEnv On Order allow,deny Allow from all </Location> ~/handlers/db.pl: use APR::Pool(); use Apache::DB (); Apache::DB->init();

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 contemplating the Monastery: (8)
    As of 2015-07-04 15:53 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 (60 votes), past polls