Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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
best XML parser in 5.18
2 direct replies — Read more / Contribute
by fionbarr
on May 21, 2015 at 14:54
    I have perl 5.18. what the best XML parser in the standard distribution? Thanks
Check if file exists in multiple directories
3 direct replies — Read more / Contribute
by Bama_Perl
on May 21, 2015 at 13:45
    Hi Monks, I need some wisdom with how to quickly and easily set up a for loop. Here's what I want to do. I have multiple directories, and within each of these directories, there is either a file with a certain extension, say *.txt, or there is not. What I need to do is loop through each of these directories to check if the file that has a *.txt extension exists, and if that file does exist, I need to copy another file within that directory -- let's call that file $out. Here's my code setup:
    #!/usr/bin/perl use warnings; $out = "outFile"; $newdir = $newdirectory; open(TABLEA, "dirlist"); @tablea = <TABLEA>; foreach $dir (@tablea) { chdir $dir; if (glob("*.txt")) { system("mv $out $newdir"); } }
    So, the directory list is set as an array, @tablea, and each directory is called $dir. If the file w/ extension *.txt exists, mv the $out file (within that directory) to the new directory, $newdir. Repeat the check for each directory. If run this script, nothing gets sent to new directory, so I was wondering how I could improve this script so that this script runs correctly? Thanks.
Parse Json using perl
3 direct replies — Read more / Contribute
by user786
on May 21, 2015 at 11:50

    I want to parse the following json output :

    My script executes a command and the command provides the json output

    im using perl json module.

    the output looks like below

    [ { "wan" : 0, "lan" : 0, "name" : "HTTP", "wan1" : 0, "lan1" : 0 } ]

    From my test script ,when i pass 'wan1' as argument i need to get 0 as the output

    use stricts; use warning; use json; # function : sub get_stats { my ($self,$option) = @_; my $cmd = 'cmd'; #command goes here $self->execute($cmd); #$self->output() contains the json output. my $decoded = decode_json($self->output() ); my @out = @{ $decoded->{$self->output()} }; foreach my $line ($self->output( ) ); print $line -> {$option} . "\n" ; }

    Function call

    $self->{'stats_obj'} = Statistics->new( ip => "ip addr"); my $result = $self->{'stats_obj'}->get_stats('wan'); INFO('Status of the task is :' . $result );
    When the script executes it doesn't return anything. any suggestions please
how to insert new line in text file after regex match?
2 direct replies — Read more / Contribute
by perl_student_g
on May 21, 2015 at 06:41

    Perl Gurus...

    Please suggest me some idea to write particular statement after certain lines of regex match...

    (1)first line. (2)second line. (3)third line. (4)fourth line. (5)fifth line.

    when it finds regex "first", then output need to be like this...

    (1)first line. (2)second line. yes, first word is found (3)third line. (4)fourth line. (5)fifth line.

    Give me some example codes which may guide me to write the required code for my requirement??

ssl cookies
1 direct reply — Read more / Contribute
by bigup401
on May 21, 2015 at 06:34

    How to ensure that cookies are always sent via SSL

Flickr OAuth module and testing
2 direct replies — Read more / Contribute
by CountZero
on May 21, 2015 at 02:25
    Dear Brothers and Sisters in Perl!

    I have written (the basics of) a module to perform OAuth authentication on Flickr. There are already a few modules that can do this but they all use the old API and I wanted to write one that is more up-to-date.

    Anyhow, it basically works (except for a few hickups), so I thought it might be a candidate for CPAN.

    However, as this module is all about OAuth authentication, any tests I write will have to contact the Flickr server and ... authenticate. Putting IDs and passwords in the module doesn't seem a good thing to do. The only way out of this seems to open a "dummy" account on Flickr and using that. That will protect my personal account but will allow anyone to put anything on Flickr under an account I have opened.

    Anyone has a better solution?


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Net::Jabber module, problem
2 direct replies — Read more / Contribute
by ICh
on May 21, 2015 at 02:09

    Hi, everybody!

    I tried to study the Net::Jabber module; unfortunatelly, the example died:

    Cannot resolve linux-cf8p: at /usr/lib/perl5/vendor_perl/5.20.1/XML/ line 409

    This name is the name of my computer. The line reads:

    my $address = gethostbyname($hostname) || die("Cannot resolve $hostname: $!");

    Therefore, the built-in gethostbyname cannot resolve the real name of my computer.

    No idea what to do.

    Thanks a lot.

Strange errors in CPAN modules when running on Windows 8.1
3 direct replies — Read more / Contribute
by schweini
on May 20, 2015 at 20:56

    I just switched to Windows 8 with Strawberry perl.

    So I installed a couple of modules via Stawberry perls cpan, and Im getting errors and warning left and right.

    As an example, I am trying to hook up a LeapMotion to perl using the company provided Device::Leap, and get errors like:

    Use of uninitialized value $BUFF in string eq at C:/Strawberry/perl/si +te/lib/Device/ line 40. substr outside of string at C:/Strawberry/perl/site/lib/Device/ + line 115.

    Which seems odd, considering that that module is not doing anything fancy - just a bit of socket reading. The authors even explicitly turned on warnings and strict, so they would have seen these errors, too.

    Even more shockingly, Im trying to talk to an Arduino using Win32::SerialPort, and I get errors like:

    Second Write attempted before First is done at line 55. Use of uninitialized value $written in numeric ne (!=) at C:/Strawberr +y/perl/site/lib/Win32/ line 1580.

    Apart from the fact that serial communications arent working, the "uninitialized value" error seems out-of place for such a popular module.

    On a hunch, I tried running the same programs from an elevated command window, but I get the same errors.

    Is there something I am missing? Is this a Win8.1 issue? Some new perl version thing?

LWP Can't connect to
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 20, 2015 at 17:11
    Since two days i can't generate bitly url. Here is the error i am having:
    $VAR1 = bless( { '_content' => 'Can\'t connect to +3 LWP::Protocol::https::Socket: SSL connect attempt failed with unkn +own error error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unkn +own message digest algorithm at /usr/local/share/perl/5.10.1/LWP/Prot +ocol/ line 51. ', '_rc' => 500, '_headers' => bless( { 'client-warning' => 'Internal +response', 'client-date' => 'Wed, 15 Apr +2015 18:08:08 GMT', 'content-type' => 'text/plain' }, 'HTTP::Headers' ), '_msg' => 'Can\'t connect to', '_request' => bless( { '_content' => '', '_uri' => bless( do{\(my $o = +' +url=LONG_URL')}, 'URI::https' ), '_headers' => bless( { 'user-a +gent' => 'libwww-perl/6.04' }, 'HTTP: +:Headers' ), '_method' => 'GET' }, 'HTTP::Request' ) }, 'HTTP::Response' );
    cat /etc/ Ubuntu 10.04.4 LTS openssl version -a OpenSSL 0.9.8k 25 Mar 2009 built on: Mon Aug 18 16:08:20 UTC 2014 platform: debian-amd64 options: bn(64,64) md2(int) rc4(ptr,char) des(idx,cisc,16,int) blowfi +sh(ptr2) compiler: cc -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT + -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -O3 -Wa,--noexec +stack -g -Wall -DMD32_REG_T=int -DOPENSSL_BN_ASM_MONT -DSHA1_ASM -DSH +A256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM apt-cache policy openssl openssl: Installed: 0.9.8k-7ubuntu8.21 Candidate: 0.9.8k-7ubuntu8.27 Version table: 0.9.8k-7ubuntu8.27 0 500 lucid-updates/main Packa +ges 500 lucid-security/main Pac +kages *** 0.9.8k-7ubuntu8.21 0 100 /var/lib/dpkg/status 0.9.8k-7ubuntu8 0 500 lucid/main Packages $ perl -MIO::Socket::SSL -e 'print $IO::Socket::SSL::VERSION' 1.74 $ perl -MIO::Socket::SSL -e 'print $Net::SSLeay::VERSION' 1.48 $ perl -MIO::Socket::SSL -e 'print $LWP::Protocol::https::VERSION' + $ perl -MLWP -le "print(LWP->VERSION)" 6.04 $ perl -MIO::Socket::SSL -e 'print Net::SSLeay::OPENSSL_VERSION_NU +MBER()' 9470143
    Any insight appreciated.
storing records of data structure in perl?
5 direct replies — Read more / Contribute
by redss
on May 20, 2015 at 16:23
    Hi Monks! I want to create a database-type data structure and store records in a stack then access the values later. I guess the best way would be an array of objects or an array of hashes? Here's what I have so far
    my $obj = bless( { 'name' => 'joe blow', 'address' => '1 main street', 'city' => 'Miami' }, 'my_type' ), push( @$var, $obj );
    My question is, is this the easiest way to do it, and how would I later access the values for each record?

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!
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2015-05-24 09:36 GMT
    Find Nodes?
      Voting Booth?

      In my home, the TV remote control is ...

      Results (472 votes), past polls