Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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
Email Module
4 direct replies — Read more / Contribute
by caseycole589
on Jul 31, 2015 at 03:16

    I'm trying to convince my work to use Perl for our email in a web app running on asp.net is this do able or does any one have advice/opinions. How hard is it to get something like this working on a windows server? Any input would be appreciated. I know I could do this easily in c# and probably should, but I'm looking for any excuse to get Perl running on our servers. That way I can have an excuse for using it on more projects moving forward.

Command line perl software development
4 direct replies — Read more / Contribute
by anomilie
on Jul 30, 2015 at 20:51
    Hi PerlMonks, I have a few perl scripts that I want to turn into a command line program that others can downlaod and use. I'm familiar with command line arguments etc. Also I know of scrum and agile, which its what I'm looking for either. The blanks that I am currently having is what is need to transition this code to an executable. How does the installation of subroutines work? how should I structure my code collection? Your help is much appreciated.
perlrun: -a implicitly sets -n
2 direct replies — Read more / Contribute
by 1nickt
on Jul 30, 2015 at 19:10

    Hi all, in perlrun under the documentation for the -a switch it states:

    -a implicitly sets -n.

    My testing seems to show this is not the case:

    $ cat test.dat foo bar baz quux $ perl -wMstrict -M5.010 -ane 'say $F[0]' test.dat foo baz $ perl -wMstrict -M5.010 -ae 'say $F[0]' test.dat Variable "@F" is not imported at -e line 1. Global symbol "@F" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

    Am I missing something?

    The way forward always starts with a minimal test.
stat on file name containing single quotes
5 direct replies — Read more / Contribute
by perlpipe
on Jul 30, 2015 at 17:21

    On my windows 7 system I have a directory named:

    E:\Music\Ray LaMontagne\2010 - God Willin' & The Creek Don't Rise

    In my program the variable $fn contains the above string. When I do a stat on that variable I get an undefined return value. The same with -d or -f as in:

     @s=stat $fn;

    or

    if (-d $fn) {print "Directory"}

    Is there any way to get the stat to work?

    I am running activestate perl 5.16.2 with a "use 5.12.0".

Net::SSH2 limitation?
1 direct reply — Read more / Contribute
by bbarrette
on Jul 30, 2015 at 17:04
    Greetings Monks, I am having a hard time tracking down this issue I am having with the Net::SSH2 module. Basically, my code will read in a file containing information to be programmed into a menu-driven network device. The code will iterate through about 21 lines before simply exiting in the middle of a print statement. I am positive it is not due to faulty file input as I can replicate the issue with any file exceeding 21 lines. I'd like to know if there is any kind of debugging I can do that will show why the program is crashing. All code is contained below:
    #!/usr/bin/perl use 5.010; use strict; use warnings; use Net::SSH2; use Data::Validate::IP; #Variables my $host = $ARGV[0]; my $tacacsusername = $ARGV[1]; my $tacacspassword = $ARGV[2]; my $fh = $ARGV[3]; my $validator = Data::Validate::IP->new; if (@ARGV != 4 || !$validator->is_ipv4($host)) { print "Invalid arguments, exiting."; exit; } open(my $data, '<', $fh) or die "Could not open '$fh' $!\n"; my $ssh = Net::SSH2->new(); $ssh->connect($host, 22); $ssh->auth_password($tacacsusername, $tacacspassword); if($ssh->auth_ok) { my $channel = $ssh->channel(); $channel->blocking(0); $channel->shell(); print $channel "network\n"; #Enter network context print $channel "ddelete\n"; #Clear DAT table print $channel "yes\n"; #Confirm clearing DAT sessions print $channel "b\n"; #Return to main context print "$_" while <$channel>; #Print output to console #Iterate the CSV file line by line while (my $line = <$data>) { chomp $line; my @fields = split "," , $line; print $channel "subscribers\n"; #Enter subscriber context print $channel "add\n"; #Add subscriber print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[0]\n"; #Hostname print $channel "1\n"; # Type of Profile 1=Device print $channel "$fields[2]\n"; #IP Address print $channel "\n"; #Subnet print $channel "\n"; #User Definable 1 print $channel "\n"; #User Definable 2 print $channel "\n"; #Upstream Bandwidth in kbps print $channel "\n"; #Downstream Bandwidth in kbps print $channel "\n"; #QOS Policy print $channel "$fields[3]\n"; #VLAN print $channel "\n"; #Proxy arp print $channel "\n"; #SMTP Redirection print $channel "b\n"; #Exit subscriber context print "$_" while <$channel>; #Print output to console if(scalar(@fields) > 5 && $fields[4] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[4]\n"; #SNMP Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[5]\n"; #SNMP External port print $channel "UDP\n"; #UDP on first pass for SNMP print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } if(scalar(@fields) > 7 && $fields[6] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[6]\n"; #MGMT Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[7]\n"; #MGMT External port print $channel "TCP\n"; #TCP on second pass for MGMT print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } if(scalar(@fields) > 9 && $fields[8] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[8]\n"; #MGMT Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[9]\n"; #MGMT External port print $channel "TCP\n"; #TCP on second pass for MGMT print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } else { print $channel "b\nb\n"; #Return to main context } print "$_" while <$channel>; #Print output to console } print $channel "b\n"; print $channel "logout\n"; print "$_" while <$channel>; print "\n"; $channel->send_eof(); $channel->close(); $ssh->disconnect(); } else { print "ERROR: Please verify credentials as the connection to the +gateway failed\n"; }
Unable to figure out - undefined value as a HASH reference
1 direct reply — Read more / Contribute
by Audar
on Jul 30, 2015 at 14:52

    Hello Monks,

    I am unable to figure out the issue with my code.
    I am passing an object to a subroutine - '_predecessors_complete' below, however, I get the following error in a certain case, marked below in the code with '--this line --' -

    Can't use an undefined value as a HASH reference at Steps.pm line 264, <OEM2015FLAG> line 1.

    The case occurs when I pass in a 'job' value that doesn't exist in the hash of all jobs. So, I tried checking if the job exists in the hash, using the 'if' exists' code.

    Question is, which value exactly would be undefined for me to get this error message? I am printing $p here, and it is definitely defined.

    OUTPUT -
    p : JOBNAME1

    Can't use an undefined value as a HASH reference at Steps.pm line 264, <OEM2015FLAG> line 1.

    CODE -

    my $rv = $self->_predecessors_complete( $self->predecessors ); ##$self +->predecessors is a reference to a hash sub _predecessors_complete { my ( $self, $predecessors ) = @_; while ( my $p = shift @{ $predecessors } ) { print "\np : $p\n"; --this line -- if ( ! exists $self->steps->{$p} ) { print "\nThe job $p has not been defined in the Scheduler!\n +"; return(100); } else {
Rolling variable
7 direct replies — Read more / Contribute
by artperl
on Jul 30, 2015 at 09:35
    Dear Perl monks, I would like to seek recommendation on what could be a good solution here... I would like to monitor file count in a specific directory & record the count every hour. I would need to keep that counts somewhere for another calculation but I would like to keep only the last 8 counts, meaning throw away the oldest data & just keep the last 8 records. How can I effectively do this in perl? Thanks much!...
Comparing two files and editing it.
3 direct replies — Read more / Contribute
by rormonk
on Jul 30, 2015 at 09:08
    Hi Monks!

    I'm trying to write a script that compares File A and File B line by line. But when comparing it only takes into account the first 3 characters of every line and ignores the others. When the first 3 characters are absent on a file it skips a line to align it with the other file. The line absent on a file is written to another new file.

    Example:

    File A     File B

    111 abc     111 pqr

    111 def     111 stu

    222 ghi     111 vwx

    223 jkl     222 yza

    345 mno    345 bcd

    _________________

    Output should be:

    File A     File B

    111 abc     111 pqr

    111 def     111 stu

                      111 vwx

    222 ghi     222 yza

    223 jkl

    345 mno     345 bcd

    _________________

    File that is created:

    111 vwx

    223 jkl

    I'm having a hard time figuring out how to do this. Please Help!

Optimize bit stream conversion
2 direct replies — Read more / Contribute
by Monk::Thomas
on Jul 30, 2015 at 07:46

    Hello fellow monks

    I have a sequence of bits that I want to convert back into actual values. I found a working algorithm, but there's probably an easier way to achieve what I want.

    Input format: 0 and 1's in big-endian order. The number of bits may or may not equal multiples of 8.

    Output format: Convert all groups of 8 into actual value, remaining bits must be kept. (Converted values can be any ASCII value, UTF-8 is not relevant.)

    Sample script

    #!/usr/bin/perl use strict; use warnings; # store 'A' and 'B' as a bitstream # (bit groups are stored big endian!) my @bits = ( 1, 0, 0, 0, 0, 0, 1, 0, # A / 0x41 / 0b01000001 0, 1, 0, 0, 0, 0, 1, 0, # B / 0x42 / 0b01000010 1, 1, 0, 0, 1, 0, 1 # incomplete byte ); my $data; while (@bits >= 8) { # fetch bit group my @eightbits_be = splice @bits, 0, 8; # convert to little endian my @eightbits_le = reverse @eightbits_be; # generate binary representation my $binary = '0b' . join q{}, @eightbits_le; # convert binary representation into actual value my $value = chr oct $binary; $data .= $value; } printf "data: %s\n", $data; # AB printf "bits: %s\n", join ', ', @bits; # 1, 1, 0, 0, 1, 0, 1
    The generated/exprected output is:
    data: AB
    bits: 1, 1, 0, 0, 1, 0, 1
    
Connection issue to the SQL Server in Azure from perl installed in CentOS
1 direct reply — Read more / Contribute
by m_pant0808
on Jul 30, 2015 at 05:42
    Hi All,

    Want to connect to the SQL Server DB available in the Azure from the perl installed in CentOS 7.

    I wan using The CentOS 7 from Oracle VirtualBox. This VirtualBox I have installed in Windows 8.1.

    When I was trying to connect same from perl installed in the master OS, i.e.: Windows 8.1, it was working fine. But, then why it is failing in when I was trying to connect the same from the Oracle VirtualBox?

    Do, I need to add trusted IP to Azure for Oracle VirtualBox (value of inet)?

    I was receiving the following error:
    ---------------------------------------------------------------------------------------------------------------------
    DBI connect('Driver={SQL Server Native Client 11.0};Server=tcp:<server>.database.windows.net,1433;Database=<database>;Uid=<u_name>@<server>;Pwd=<pswrd>;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;','',...) failed: [unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired (SQL-HYT00) [state was HYT00 now 08001]
    [unixODBC][Microsoft][SQL Server Native Client 11.0]TCP Provider: Error code 0x2726 (SQL-08001)
    [unixODBC][Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (SQL-08001) [state was 08001 now 01S00]
    [unixODBC][Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (SQL-01S00) at odbc_perl.pl line 9.

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: (5)
    As of 2015-08-03 02:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The oldest computer book still on my shelves (or on my digital media) is ...













      Results (21 votes), past polls