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
variables passed from main to package
1 direct reply — Read more / Contribute
by FryingFinn
on Feb 21, 2018 at 20:38
    I trying to get an application to set a couple of Global (?) variable that will be used in package subroutines. I thought I could use  $main::DEBUG my test main is
    #!/usr/bin/perl ## this is perl5.16 my $DEBUG = 1233; my $VERBOSE=5; use strict; use warnings; use Getopt::Long; my $Usage = "this is Usage"; Getopt::Long::GetOptions( 'd=i' => \$DEBUG, 'v=i' => \$VERBOSE ) or die "Incorrect u +sage! $Usage\n"; print "in MAIN DEBUG is $DEBUG \n"; print "In Main VERBOSE is $VERBOSE \n"; use lib "../lib"; use myApp; myApp::testprint(); myApp::testprint2();
    The code for is
    package myApp; my $DEBUG = $main::DEBUG; my $VERBOSE = $main::VERBOSE; print " has DEBUG [$DEBUG]\n"; print " has VERBOSE [$VERBOSE]\n"; 1; sub testprint { print "in myApp::testprint DEBUG is [$DEBUG]\n"; print "in myApp::testprint VERBOSE is [$VERBOSE]\n"; } sub testprint2 { my $DEBUG = $main::DEBUG; my $VERBOSE = $main::VERBOSE; print "in myApp::testprint2 DEBUG is [$DEBUG]\n"; print "in myApp::testprint2 VERBOSE is [$VERBOSE]\n"; }
    The results.
    ./xVERBOSE has DEBUG [] has VERBOSE [] in MAIN DEBUG is 1233 In Main VERBOSE is 5 in myApp::testprint DEBUG is [] in myApp::testprint VERBOSE is [] in myApp::testprint2 DEBUG is [] in myApp::testprint2 VERBOSE is []
    any help would be appreciated tks gerry
Using Net::SFTP
3 direct replies — Read more / Contribute
by slugger415
on Feb 21, 2018 at 16:41

    Ok I'm having a dummy moment here. Wanting to use Net::SFTP. I looked here: but frankly don't understand how to do it.

    Here's some of my code:

    my $sftp = Net::SFTP->new($host, %args); print $sftp->ls('.'), $/;

    It's clearly connecting successfully, but here's what I get:


    I've tried assigning that to a hash, array and variable but can't seem to do anything with it. What am I missing?

Undefined value error
1 direct reply — Read more / Contribute
by clarkmurph
on Feb 21, 2018 at 12:54

    Hello, I get the following error when I execute the below script "Can't call method "mail" on an undefined value at ./recalert.plx line 24, <RECCHK> line 9." I did not write the original perl script, I just modified the email addresses to work in my environment, and the email addresses in the below script are sanitized. The script has worked for about three years without issue, I really have no perl experience, and not sure what the error means, or how to fix it/ Please help

    #!/usr/bin/perl -w $from = ''; $to = ''; $servername = ''; # $user ='username'; # $pwd ='password'; open RECCHK, "/tmp/statusmon.eml"; @recchkvar = <RECCHK>; use Sys::Hostname; my $host = hostname(); my $host1 = uc($host); open STDERR, '>&STDOUT'; #redirect STDERR output to STDOUT use Net::SMTP; $smtp = Net::SMTP->new("$servername", Debug => 1); ### Enable below if authentication required and set parameters above # $smtp->datasend("AUTH LOGIN\n"); # $smtp->datasend("$user\n"); # $smtp->datasend("$pwd\n"); sleep(2); $smtp->mail("$from"); $smtp->to("$to"); $smtp->data; $smtp->datasend("Subject: 79XX/69XXC/WB3 InfiniStream $host1 has an is +sue, and requires investigation \n"); foreach $line (@recchkvar) { $smtp->datasend("$line\n"); } close RECCHK; $smtp->dataend; $smtp->quit
Make a CPAN module
4 direct replies — Read more / Contribute
by mpersico
on Feb 21, 2018 at 09:42
Regexp issue
3 direct replies — Read more / Contribute
by QuasarD
on Feb 21, 2018 at 05:55
    Hi, i have some issues with a regular expression:
    use strict; use warnings; my $string1 = '"18/02/2018"'; print $string1 . "\n" if ($string1 =~ m/^"{1}[^"{1}]/); my $string2 = '"28/02/2018"'; print $string2 . "\n" if ($string2 =~ m/^"{1}[^"{1}]/); exit;
    The scalar string1 doesn't match...but why??
Replace a patern_2 in 30 lines from the line with the patern_1 founded
2 direct replies — Read more / Contribute
by thao4
on Feb 21, 2018 at 05:05

    Hi all, I am new in perl. I need do somthing in perl: exemple: - search a patern "CADRE 1.1 CPU" in one file.txt - incremente +30 lines from the line with the patern found - replace the new patern "Model Regle" by "Heath Rule A" in this new line (30 lines after the line with patern "CADRE 1.1 CPU" Could you help me, please, thank you very much exemple of the text

sns sender id
1 direct reply — Read more / Contribute
by bigup401
on Feb 21, 2018 at 05:05

    does anyone has good documentation of this coz cant find it anywhere

    how to add sender id coz sns has that funcation of sender id

    this is like sending using default sender id of sns

    use Paws; my $paws = Paws->service('SNS'); $paws->Publish( Message => "test", PhoneNumber => "+1XXXXXXXXXX", );
Opening bad Excel files
4 direct replies — Read more / Contribute
by Arik123
on Feb 21, 2018 at 02:30

    I have an excel file which I need to extract data from. When I open it (with Spreadsheet::XLSX) it reports an empty file - no worksheets. This is not correct. Opening it with Excel itself shows that there is data.

    The problem might be that the file wasn't created by Excel itself - it may have been created by another program, which pretends to create 100% compatible Excel files.

    Is there any way to convert such files to valid Excel files, or is there another Perl module that can open and process them? I need a permanent solution, to process many such files automatically.

    The file can be found here:

    Thank you very much!

Original name of a PAR-Packed shared object file?
1 direct reply — Read more / Contribute
by ek15
on Feb 20, 2018 at 16:30

    Hi all,

    I am seeing the below error when trying to run an executable that I packed with PAR Packer (pp). How can I find out the original name of the shared object file I'm trying to get more clues as to why this error is coming up. Thanks.

    [root@ektest1 DarkEther-v1.15.3]# ./switchscan local/mlnx cfgfile=192. +168.20.141.cfg Can't find 'boot_IO' symbol in /tmp/par-726f6f74/cache-b7a72e3a0413c42 +480d6dae1f533764a0bf93415/ at /usr/local/share/perl5/PAR/ line 78. Compilation failed in require at /usr/lib64/perl5/IO/ line 26 +6. BEGIN failed--compilation aborted at /usr/lib64/perl5/IO/ lin +e 266. Compilation failed in require at /usr/lib64/perl5/IO/ line +101. BEGIN failed--compilation aborted at /usr/lib64/perl5/IO/ l +ine 101. Compilation failed in require at /usr/lib64/perl5/IO/ line 133. BEGIN failed--compilation aborted at /usr/lib64/perl5/IO/ line +133. Compilation failed in require at -e line 138.
Regex match multiple line output
4 direct replies — Read more / Contribute
by bartrad
on Feb 20, 2018 at 10:32

    Hopefully a relatively simple one for somebody, but I've been staring at it too long it's all now a blur. I have the following output generated and it's either:


    ====================================================================== +======== LDP Sessions ====================================================================== +======== Peer LDP Id Adj Type State Msg Sent Msg Recv Up Tim +e ---------------------------------------------------------------------- +-------- ---------------------------------------------------------------------- +-------- No Matching Entries Found ====================================================================== +========


    Output 2

    ====================================================================== +======== LDP IPv4 Sessions ====================================================================== +======== Peer LDP Id Adj Type State Msg Sent Msg Recv Up Tim +e ---------------------------------------------------------------------- +-------- Targeted Established 822443 822431 273d 15:02:2 +0 ---------------------------------------------------------------------- +-------- No. of IPv4 Sessions: 1 ====================================================================== +========

    I'm trying to match using the following code to trigger an IF statement. Basically I'm looking for if the output contains an IP address then stop, otherwise keep going. But, it seems my IF statement returns true even if nothing that looks like an IP address is returned. I've been on regex101 to test my matching and it checks out there, but must be something obvious!

    if ( $output1 || $output2 =~ m/\d+\.\d+/gm ) { print "Found something"; exit; } else { print "Do this instead";

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.