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 tk entry widget to get arguments for perl script.
1 direct reply — Read more / Contribute
by john.tm
on Jul 13, 2014 at 09:28
    Hi, I have a script which via the command line asks the user for the the required Year,Month and Day and then processes a file with those details.
    #!/usr/bin/perl #use strict; use warnings; use Spreadsheet::WriteExcel; use File::Copy qw(copy); open(STDERR, ">&STDOUT"); #Set-up Files my $yyyy = $var[0]; print "Enter year in YYYY format:\n"; $yyyy = <STDIN>; chomp $yyyy; my $mmm = $var[1]; print "Enter Month in 3 letter abr format\njan,feb,mar,apr,may +,jun,jul,aug,sep,oct,nov,dec:\n"; $mmm = <STDIN>; chomp $mmm; my $dd = $var[2]; print "Enter day in number format\n01,02,03,04 etc:\n"; $dd = <STDIN>; chomp $dd; <\code> <p> How can i create and bind a Tk pop up entry widget for this, I have c +reated the browseEntry widget but need help on binding it to the vari +ables. <code> #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $mw = MainWindow -> new; $mw->geometry("380x155"); $mw->title("Adhoc Failures"); my $browseEntryyear = $mw ->BrowseEntry( -label => 'Select year :', -relief => 'sunken', #-variable => \$var0, -state => 'readonly', -autolistwidth => '1', -justify => 'right', -buttontakefocus => 1, -relief => 'sunken') -> pack( -ipadx => 33, -side => 'top', -fill => 'x', -anchor => 'e', -expand => 1); $browseEntryyear -> insert('end', qw(2013 2014 2015 2016 2017 +2018 2019 2020)); my $browseEntrymonth = $mw ->BrowseEntry( -label => 'Select Month :', #-variable => \$var1, -state => 'readonly', -autolistwidth => '1', -justify => 'right', -buttontakefocus => 1, -relief => 'sunken') -> pack( -ipadx => 33, -side => 'top', -fill => 'x', -anchor => 'e', -expand => 1); $browseEntrymonth -> insert('end', qw(Jan Feb Mar Apr May Jun +Jul Aug Sep Oct Nov Dec)); my $browseEntryday = $mw ->BrowseEntry( -label => 'Select Day :', #-variable => \$var2, -state => 'readonly', -autolistwidth => '1', -justify => 'right', -buttontakefocus => 1, -relief => 'sunken') -> pack( -ipadx => 33, -side => 'top', -fill => 'x', -anchor => 'e', -expand => 1); $browseEntryday -> insert('end', qw(01 02 03 04 05 06 07 08 09 + 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) +); my $but = $mw -> Button(-text => " Enter ", -command =>\&push_button, -relief => 'raised')->pack(-side + => "bottom",-fill => 'x'); MainLoop; #sub push_button { yourFunc($var0,$var1,$var2) };
input special characters
2 direct replies — Read more / Contribute
by kepler
on Jul 13, 2014 at 06:17
    Hi, I'm having this problem: I'm trying to input a character that will be used to separate fields for an output to a file. Example: if I input | the result string in the file will be: Field1|field2| etc... But how can I insert a special character like \t? I'm only getting: Field1\tField2\t etc... instead of the fields be separated by tabs. Is there a way to solve this? Regards, Kepler
Calling Weblogic service with WSS11
No replies — Read more | Post response
by Anonymous Monk
on Jul 13, 2014 at 05:43
    I'm trying to call a Oracle-Weblogic web service implementing wss11 message level security and I'm really having a hard time.

    I need to encrypt sections of the soap request (tags EncryptedKey,EncryptedData) as well as sign some other part (tags dsig:Signature).

    Does XML::Compile or SOAP::Lite support those features and if yes is there sample code or pointers somewhere?

    XML::Compile says that encryption is not supported but then in the module documentation it is using RSA signer

Login to BGP via Perl
2 direct replies — Read more / Contribute
by varalaxmibbnl
on Jul 13, 2014 at 01:30

    Hi Monks

    I want to login to bgp to run few commands often so i thought of making script to run those commands and i used

    Net::SSH::Perl

    to login to bgp and run a command..the script is as follows

    #!/usr/bin/perl use Net::SSH::Perl; use POSIX qw(strftime); $time = strftime "%d-%b-%Y", localtime; $host = "XXX.XXX.XXX.XXX"; $username = "user"; $password = "password"; $port = "XXXX"; $ssh = Net::SSH::Perl->new($host,port=>"$port",protocol=>2); @array = $ssh->login($username,$password); #@ary = $ssh ->cmd("show arp"); @data = $ssh->cmd("show interfaces"); print "@array\n@data\n"; @data2 = $ssh ->cmd("exit"); print "@data2\n";

    if i run the above script it will login but it prints invalid command show

    please some one suggest how to solve this problem

    Thanks in advance

sort on hash / hash / hash doesn't work
3 direct replies — Read more / Contribute
by PsySkeletor
on Jul 12, 2014 at 13:19
    Hi monks! I facing a problem what it should be easy to fix it but i don't know how. I have a script which opens a lot of log files and pull the data to different hashes. For the sake of organization, i translate the dates to epoc and organize in my hash the info using the epoc time as the second hash, to prevent duplicates and to sort the hash results to present them in chronologic order. Well, the problem its sort isn't sorting epoc numbers :(
    foreach $cat ( keys %data ) { foreach $date ( keys %{ $data{$cat} }) { print "<tr>"; foreach $data_type (sort { $a cmp $b } keys %{ $data{$cat}{$da +te} } ) { print "<td align='left'>$data{$cat}{$date}{$data_type}</td +>"; #print "<br>"; } print "</tr>"; } }
    $cat = category, i have 4, that runs. $date = its the date en epoc, this doesn't run $date_type = the type of data we are going to print, this works. The results of the sort that is not shorting are:
    EPOC IP 1405799856 79.223.46.211 1405879428 79.200.95.44 1405702121 87.149.76.154 1407101135 188.138.41.140 1406108233 82.139.192.95 1407162997 87.149.66.39 1405810508 80.187.110.214 1405791762 84.159.197.17 1405870826 2.246.106.240 1406040423 87.154.119.73 1405810525 85.22.101.198 1405620262 87.149.72.59 1405603261 178.12.215.30 1405806556 80.187.102.26
    As you can see, there is not sorting. :(
Strange behaviour with Arrays and print?
3 direct replies — Read more / Contribute
by pingufreak83
on Jul 12, 2014 at 08:55
    Hi,
    I'm currently refreshing my Perl experience by reading some books. During testing some scripts, I've noticed a strange behaviour during the following script:
    #!/usr/bin/perl binmode(STDOUT, ":utf8"); use 5.010; use strict; use warnings; use diagnostics; use utf8; my @fred; my $fred; $fred = "HALLO"; $fred[0] = "eins"; $fred[1] = "zwei"; $fred[2] = "drei"; $fred[3] = "vier"; $fred[4] = "fünf"; $fred[5] = "sechs"; $fred[6] = "sieben"; $fred[7] = "acht"; $fred[8] = "neun"; $fred[9] = "zehn"; print @fred; print "\n"; print @fred."\n";
    The output result is the following:
    einszweidreivierfünfsechssiebenachtneunzehn 10
    Why is the array counted if I use a new line?
    Is this normal and why?

    Thanks!

    Kind regards,

    Pingu
Updating hash using it's reference ...
4 direct replies — Read more / Contribute
by karthikin2asic
on Jul 12, 2014 at 04:05
    Hi, I have hash addresses in an array. Is it possible to access each of these hash addresses and add a key using references? Can you please share the code with me? Thanks, -Karthik
Is REST best?
2 direct replies — Read more / Contribute
by traveler
on Jul 11, 2014 at 16:34

    I am building a simple web tool for a client. It will query a database and display some data. They will be able to search, sort, etc., so a simple javascript tool can handle the display. I want to use perl on the back end, as I have done in other situations. It has been suggested that I implement it via REST and then I can add new features fairly easily (this client likes to request that).

    I've read modern ways of doing web services. I've also read Apache2::REST. I don't see many servers using the latter, even though it looks good. Is something better? I don't want to do it all from scratch, of course.

last_insert_id() in sybase
5 direct replies — Read more / Contribute
by Shreyak
on Jul 11, 2014 at 15:04

    i am not able to get value in last_insert_id() after insert operation in sybase database. I had to use do statement instead of prepare statement for both insert and update operations to get value from last_insert_id(). Does anyone know the reason of this behavior?

Strawberry Perl cannot locate Statistics/Basic.pm
2 direct replies — Read more / Contribute
by pimperator
on Jul 11, 2014 at 14:55
    I'm dumb

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.