Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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
INIT {$SIG{__DIE__} and Getopt::Long
5 direct replies — Read more / Contribute
by demichi
on Jul 29, 2015 at 13:16
    Hi all

    I am normally using the following line to capture the die output into a logfile.

     INIT {$SIG{__DIE__}=sub {LOG_MSG("normal",3,"GENERAL","Script died: $_[0]") and close LOG;}}

    Now I am using also Getopt::Long. I don't want to have a logfile generated if somebody is chosing the wrong parameter. Therefore I let the script die with an usage output.

    Unfortunately if somebody choses a wrong getopt parameter now - I get a log error message because of the INIT-"die" setting as the log file is not opened yet.

    Example:
    G:\development\bin>x.pl -x > 4,GENERAL,Script warning: Unknown option: x print() on unopened filehandle LOG at G:\development\bin\x.pl line 45. + ### Version:2.0.0 NAME xxx > 3,GENERAL,Script died: 1 at G:\development\bin\x.pl line 14. ### > 4,GENERAL,Script warning: print() on unopened filehandle LOG at G:\d +evelopment\bin\x.pl line 45. ### print() on unopened filehandle LOG at G:\development\bin\x.pl line 45. + ### 1 at G:\development\bin\x.pl line 14. ### G:\development\bin>

    Every line marked with "###" at the end I do not want to have as output to STDOUT.

    Do you have an ideas how can fix it? Thanks.

    kind regards de Michi

    Code:
    use strict; use warnings; use Getopt::Long qw(:config no_ignore_case bundling); # Get options / my $VERSION = "2.0.0"; INIT {$SIG{__DIE__}=sub {LOG_MSG("normal",3,"GENERAL","Script died: $_ +[0]") and close LOG;}} INIT {$SIG{__WARN__}=sub {LOG_MSG("normal",4,"GENERAL","Script warning +: $_[0]")}} # Check Flags my $flag_help; my $flag_version; my $flag_config; GetOptions ( 'h|help' => \$flag_help, 'V|VER' => \$flag_version, 'c|config=s' => \$flag_config, ) or die USAGE(); # Check flags and print usage if ($flag_version) { print "Version: $VERSION\n"; exit; } if ($flag_help) { USAGE(); exit; } open(LOG,"> SCRIPTLOG_FILE") or die ("Can't open SCRIPTLOG_FILE: $!\n" +); close LOG; ### subs sub LOG_MSG { my $par_LEVEL = shift (@_); my $par_SEVERITY = shift (@_); my $par_FUNCTION = shift (@_); my @line = @_; print "> $par_SEVERITY,$par_FUNCTION,@line\n"; print LOG "$par_SEVERITY,$par_FUNCTION,@line\n"; } sub USAGE { my ($message)=<<'MESSAGE'; NAME xxx MESSAGE print "Version:${VERSION}\n$message"; }
calculating length of the string
2 direct replies — Read more / Contribute
by GSperlbio
on Jul 29, 2015 at 05:24

    Im having sequence "CUGUACAGCCUCCUAGCUUUCC" in the file "rna.txt" i need to get the length of the sequence as 22 instead im getting 23. can anyone help me to correct this error?? this is my code:

    #!usr/bin/perl use warnings; open (RH, "<rna.txt") || die "cant open the file"; my $arr2 = <RH>; print "rna sequence is $arr2"; $len2= length($arr2); print $len2;
How to get the process Id
6 direct replies — Read more / Contribute
by vasuperl
on Jul 29, 2015 at 03:34
    Hi, I want to get the process id for the command executed in the command prompt. For example I want to execute command of "tcpdump -i any -w filename.pcap &" in the linux machine from my windows PC. Now I want to get the process id of that command. I have done telnet connection to that linux machine and able to execute that command. But i was not able to get the process id of that command to kill that process. I am new to perl. Please help me on this
Comparing specific columns from 2 files
4 direct replies — Read more / Contribute
by arunsriniv
on Jul 29, 2015 at 02:53

    Hello, I am trying to compare specific columns in 2 files so see whether the contents in one file (File1.txt) which is a master file is exact with another file (File2.txt) which is a subset of File1.

    For Example: File1.txt (Master file)

    Status1,Name1,Source1,Destination1

    Status2,Name2,Source2,Destination2

    Status3,Name3,Source3,Destination3

    .....

    .....

    File2.txt (Subset of File1.txt)

    Status1,Name1,Source1,Destination1

    Status2,Name2,Source2,Destination2

    Now, I am trying to compare only specific columns in File1 with File2 say ignore Status column and compare only the remaining columns for exactness. Any ideas are appreciated? My current code is to compare all columns between 2 files for exactness.

    my @cur_data=<FILE1>; close (FILE1); my @org_data=<FILE2>; close (FILE2); foreach $org_data(@org_data) { $flag= 1; foreach $cur_data(@cur_data) { chomp ($cur_data); chomp ($org_data); if ( $cur_data eq $org_data ) { $flag= 0; last; } } if ($flag == 1) { print " \n $org_data -->failed\n"; last; } } return $flag;
Call external script via ssh with Control::CLI, get output to calling script window
1 direct reply — Read more / Contribute
by ImJustAFriend
on Jul 29, 2015 at 02:02

    I am 100% sure I'm missing something real basic here, but after a week of trial and error, I think it's time to ask you fine folks for help.

    I am creating an automation script for work that will run from Windows laptops. It will use the Control::CLI module to ssh to the target remote servers and do the work. The script I created works wonderfully, with one minor annoyance. At a certain point in my script, I have to launch an external script that resides on one of the target servers and monitor it's progress so I know when to move on. The external script does provide feedback as it runs, which I do monitor... but my users want to see that feedback when the script is running. An example of what they currently see from my script is:

    Are you ready to let it run (y/n)? y Pre-loading started at: Tue Jul 28 16:10:13 UTC 2015 Please wait for pre-loading to finish... X records loaded into system in N seconds... X records loaded into system in N seconds... ...

    What they are asking for is to show the output of the pre-loader script, like:

    Are you ready to let it run (y/n)? y Pre-loading started at: Tue Jul 28 16:10:13 UTC 2015 Please wait for pre-loading to finish... File1 loaded... File2 loaded... ... X records loaded into system in N seconds... X records loaded into system in N seconds... ...

    The "FileN loaded" lines are printed out by the pre-loader script. The command I send to the server to launch the pre-loader looks like this:

    $s1_output = $s1_cli->cmd("/path/to/pre-loader.pl arg1 arg2 2>&1");

    How can I get the output of pre-loader.pl to display in my calling script window?

    Thanks in advance!!

Passing data to Getopt::Long
3 direct replies — Read more / Contribute
by neilwatson
on Jul 28, 2015 at 19:56

    Greetings, Is the following possible? I'm making a template for future scripts and programs. I thought it would be useful to separate the standard cli args (man, help, usage, etc) to a separate package. My first try returns an error. Why?

    #!/usr/bin/perl use strict; use warnings; use feature 'say'; use Getopt::Long; use Pod::Usage; use Data::Dumper; my $VERSION = 1; # Get standard options from reusable module my $stdopts = Std::Opts->new(); my $std_cli_arg_ref = $stdopts->get_standard_args; # Read, process, and validate cli args my $cli_arg_ref; GetOptions( $cli_arg_ref, $std_cli_arg_ref, # These two samples can be removed 'myarg=s', 'arg2=i', ); # # Modules # package Std::Opts; use strict; use warnings; sub new { my ( $class ) = @_; return bless {}, $class; } sub get_standard_args { my $self = shift; my $std_cli_arg_ref = { 'version' => sub { say $VERSION; exit + }, 'test' => sub { _run_tests(); exit + }, 'man' => sub { pod2usage( -verbose => 2, -exitval => 0 ) + }, 'dumpargs' => sub { say '$cli_arg_ref = '. Dumper( $cli_arg_ref ); exit }, 'help|?' => sub { pod2usage( -sections => ['OPTIONS'], -exitval => 0, -verbose + => 99) }, 'usage' => sub { pod2usage( -sections => ['SYNOPSIS'], -exitval => 0, -verbose + => 99) }, 'examples' => sub { pod2usage( -sections => 'EXAMPLES', -exitval => 0, -verbose + => 99) }, }; return $std_cli_arg_ref; } 1; Returns: $ ./foo.pl -du Undefined argument in option spec Error in option spec: "HASH(0x1772fc8)"

    Neil Watson
    watson-wilson.ca

User preference: To store params or not
4 direct replies — Read more / Contribute
by stevieb
on Jul 28, 2015 at 18:42

    My larger projects require params to be passed in via hashref for simplicity, but I'm wondering from a user perspective which is more convenient... storing the non-core params for continuous use, or reset the non vital ones so they have to be resent in.

    If they are stored, it requires a reset on the params that you want changed (ie. you have to reset a parameter to false on a subsequent run with the same object). What's your opinion on storing or wiping params?

Working with Confluence and LWP
4 direct replies — Read more / Contribute
by TStanley
on Jul 28, 2015 at 13:43
    My company recently bought the Confluence software from Atlassian. Confluence is a web based collaboration system, allowing users to upload
    documents and other content to their personal pages, and to provide for project teams to collaborate together and share documentation. The software
    also tracks changes to the documentation as well.

    I have been tasked with automating some tasks that occur on a daily basis, mostly updating verification reports of our various databases, and then
    publishing those to Confluence.

    Confluence has several APIs, and the easiest for me to use was the RPC-XML client, as I could do it with perl. A search of CPAN gave me the Confluence::Client::XMLRPC module. So I created the following short script, to make sure I could do what I want:
    #!C:\Perl64\bin\perl use strict; use warnings; use Confluence::Client::XMLRPC; my $version=2; Confluence::Client::XMLRPC::setApiVersion($version); Confluence::Client::XMLRPC::setRaiseError(1); Confluence::Client::XMLRPC::setPrintError(1); my $URL="https://jeeves.Mainoffice.Demoulas.Corp/rpc/xmlrpc/"; my $user="toms"; my $pass="password"; my $object = Confluence::Client::XMLRPC->new($URL,$user,$pass); $object->logout();
    which produced the following error:
    XML-RPC ERROR: Unable to connect to https://jeeves.Mainoffice.Demoulas +.Corp/rpc/xmlrpc at C:\Users\toms\Documents\Confluence\confluence.pl line 15
    After a great deal of trial and error, I got the code below working:
    #!C:\Perl64\bin\perl use warnings; use strict; use LWP::UserAgent; my $ua=LWP::UserAgent->new(ssl_opts=>{ verify_hostname => 0}); my $req = HTTP::Request->new(GET => 'https://jeeves.mainoffice.demoula +s.corp'); my $result = $ua->request($req); if($result->is_success){ print $result->content; }else{ print $result->status_line, "\n"; }
    The catch is where I create the LWP object, telling the agent to not verify the hostname of the server. If I remove the ssl_opts, it will say it can not connect due to failing the certificate verification. The Confluence client in the first bit of code uses LWP and LWP::Protocol::https to handle the http/https part of connecting to the server. What I need to figure out is how I can pass the ssl_opts.

    I am currently testing all of this on Windows 7 (64 bit), running ActiveState Perl 5.18.2


    TStanley
    --------
    People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell
hex escape Question
1 direct reply — Read more / Contribute
by mfawbush
on Jul 28, 2015 at 13:30

    Hello, I've been beating on this for a while now that I'm just plumb confused now. I'm sure it's so simple and it's right in front of me. Need to send a five byte block to serial port. The snippet of code below works, however I need to replace all the values behind the hex escape "\x" with what the user puts in from STDIN strings. I've tried pack and hex with no success. Thank you in advance for your help.

    #Works $port->write("\x01\x42\x62\x00\x01");
use File::Path qw(make_path); fails with php 5.6.11
3 direct replies — Read more / Contribute
by windjammer
on Jul 28, 2015 at 11:07

    I have recently upgraded my php from 5.3.8 to 5.6.11 (security issues requirment).

    Previous: PHP 5.3.8 (cli) (built: Sep 19 2011 13:29:27) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies Current: PHP 5.6.11 (cli) (built: Jul 15 2015 21:26:53) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies use File::Path qw(make_path);
    Any idea why this fails?

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 taking refuge in the Monastery: (9)
    As of 2015-08-01 21:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found
      past polls