Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

The Monastery Gates

( #131=superdoc: print w/ replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Difference between these regexes
5 direct replies — Read more / Contribute
by haukex
on Jul 29, 2016 at 08:36

    Fellow Monks,

    I seek your wisdom: A recent node (Re: No tools? Use Perl?!) got me wondering: Is there a difference between these three regexes that I am missing, primarily in terms of what they match? In particular I'm interested in the first two - I understand the first and third regexes, but am not an expert on look-arounds.

    1. /<(.*?)>/s
    2. /<((?:(?!>).)*)>/s
    3. /<([^>]*)>/s

    I have yet to find a difference - I am not sure if there even is one - but I'm probably not being creative enough in my test cases...

    -- Hauke D

Crypt() usage
3 direct replies — Read more / Contribute
by fionbarr
on Jul 28, 2016 at 12:04
    Is the 'crypt' function identical on Windows and *nix platforms?
$_[OBJECT] 's example
1 direct reply — Read more / Contribute
by liuweichuan
on Jul 27, 2016 at 23:30
    I have do some example about POE; but about this point on $_OBJECT parameter, i can't know clear. i make a, contains a object:
    package baozi; sub new{ my $class = shift; my $self = bless {}, $class; } sub fun1{ my $self = shift; print "fun1......baozi \n" } 1
    then try the $_OBJECT in other pl,
    use POE; use baozi; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield('next1')}, next1 => sub { print "tick ... \n"; $_[KERNEL]->delay(next2 => 1); }, next2 => \&next2, next3 =>\&baozi, }, ); POE::Kernel->run(); sub next2{ print "tick 0 ... \n"; $_[KERNEL]->yield('next3'); } sub baozi{ my $self = $_[OBJECT]; print $self; $self->baozi::fun1(); }
    I think 'next2' call 'next3' handler, and run sub baozi.$self->baozi::fun1(); can call package baozi's fun1. but I know my thinking is wrong, plz tell me more right, and help me understand $_OBJECT, thank you.
Perl Code Changes Behavior if Two Subroutine definitions are swapped
2 direct replies — Read more / Contribute
by rkabhi
on Jul 27, 2016 at 10:04

    Hello Perl Monks !!

    I came across a really unexpected issue while developing a code to read a netlist file containing just few lines. I have written down system details, the code and input file and finally I describe the problem at the end

    System and Setup Info: Linux RHEL6 Perl Version 5.10.1



    #!/usr/bin/perl use strict; use warnings; use Switch; #Common Variable Initialization my %DeviceList = (); my $netlist_file = "/home/abhishek_r/Tool_Development/Voltrace/Perl/ne +tlist.scs"; my @InbuiltDeviceList = ('resistor','capacitor','inductor','vsource',' +isource'); my @subcktslist = getSubcktList($netlist_file); print @subcktslist; TraceSubcktDevices($netlist_file); sub getSubcktList{ my $netlist = $_[0]; my @subckts = (); open(READ_NETLIST, "<$netlist") or die "Couldn't open netlist file + for read, $!"; while(<READ_NETLIST>){ chomp; s/^\s+//; #To remove leading blanks (if any) in the line #ignore line if it contains comments or initializing words for + spectre switch() { case /^[*\/]/i {next;} case /simulator\s+lang/i {next;} case /^include/i {next;} } if(/subckt/i) { my $line = $_; my @words = split(/\s+/,$line); #Split the read line in $_ + with white spaces as delimiter my $nameindex = 1; #Default index where subckt name i +s usally found if(/inline/i){ #To change name index if subckt de +finition includes inline $nameindex = 2; } push @subckts,$words[$nameindex]; } } close(READ_NETLIST); return @subckts; } sub TraceSubcktDevices{ #Input: (netlist_file, subcktname, key +_init) where subcktname is the name of subckt that needs to be traced + in the netlist my $netlist = $_[0]; my $subcktname = "hello"; $subcktname =~ s/^\s*|\s*$//g; #To remove all leading and trainin +g blanks from input subckt name my $key_init = $_[2]; my $skip=0; #Default Skip status for netlist l +ine. 0 indicates "don't skip" and is set for TOPLEVEL if($subcktname){ #Set skip flag if input subckt name is not + blank i.e. the tracing is not required at TOPLEVEL $skip = 1; } open(READ_NETLIST, "<$netlist") or die "Couldn't open netlist file + for read, $!"; while(<READ_NETLIST>){ $skip = $skip + 1; print "Hello"; } close(READ_NETLIST); }

    Input File: netlist.scs

    // Generated for: spectre // Generated on: Jul 26 15:10:24 2016 // Design library name: custom // Design cell name: TOPLEVEL // Design view name: schematic simulator lang=spectre global 0 //--------------------------------// // Library name: custom // Cell name: inv // View name: schematic subckt inv IN OUT VDD VSS M0 (OUT IN VSS VSS) nch l=60n w=200n m=1 nf=1 sd=200n ad=3.5e-14 \ as=3.5e-14 pd=750n ps=750n nrd=0.5 nrs=0.5 sa=175n sb=175n sca +=0 \ scb=0 scc=0 M2 (OUT IN VDD VDD) pch l=60n w=200n m=1 nf=1 sd=200n ad=3.5e-14 \ as=3.5e-14 pd=750n ps=750n nrd=0.5 nrs=0.5 sa=175n sb=175n sca +=0 \ scb=0 scc=0 ends inv // End of subcircuit definition. // Library name: custom // Cell name: BUF_DELAY // View name: schematic subckt BUF_DELAY IN OUT VDD VSS I1 (net11 OUT VDD VSS) inv I0 (IN net11 VDD VSS) inv ends BUF_DELAY // End of subcircuit definition. // Library name: custom // Cell name: INV_DELAY // View name: schematic subckt INV_DELAY IN OUT VDD VSS I2 (net08 OUT VDD VSS) inv I1 (net11 net08 VDD VSS) inv I0 (IN net11 VDD VSS) inv ends INV_DELAY // End of subcircuit definition. // Library name: custom // Cell name: TOPLEVEL // View name: schematic I2 (BUF_IN BUF_OUT VDD VSS) BUF_DELAY I3 (INV_IN INV_OUT VDD VSS) INV_DELAY I4 (INV_IN net8) isource type=pwl wave=[ 1u 1 2u 2 ] V3 (VSS 0) vsource dc=0 type=dc V2 (INV_IN 0) vsource dc=0 type=dc V1 (BUF_IN 0) vsource dc=5 type=dc V0 (VDD 0) vsource dc=5 type=dc R0 (net8 VSS) rm1w l=10u w=2u mf=1 C0 (net8 0) capacitor c=1p //----------------- Entering Netlist Footer -------------------//

    The Problem: In the code, there are two subroutines getSubcktList() and TraceSubcktDevices(). The former subroutine works fine. The latter subroutine (i.e. TraceSubcktDevices()) is showing a very unexpected behavior. I have listed my observations below:

    1) If the above code is run "as is" making sure that correct path of netlist.scs file is supplied at the beginning, the code gets stuck (I use Linux command line to run the code) with no response

    2) If I swap the subroutines, i.e. define TraceSubcktDevices() first and getSubcktList(), the code works fine printing "Hello" as many times as the number of lines in input file netlist.scs

    Can anyone please let me know why this is unexpected behavior being observed?

    Thanks !!


    update: edited/code tags by stevieb

Error in HTTPS connection with error: No connection could be made because the target machine actively refused it. at C:/Perl/lib/LWP/Protocol/ line 47
2 direct replies — Read more / Contribute
by jliu5
on Jul 26, 2016 at 11:36

    Hi Monks,

    I am trying to create a REST client to do a simple GET service at a https server, but got this error.

    Here is my sample code, please advice.:

    #! /usr/bin/env perl use REST::Client; use MIME::Base64; my $username = 'me'; my $password = 'me!!'; my $headers = {Accept => 'application/xml', Authorization => 'Basic ' +. encode_base64($username . ':' . $password)}; my $client = REST::Client->new(); $client->getUseragent->ssl_opts(verify_hostname => 0); $client->getUseragent->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE); $client->getUseragent->no_proxy('server_ip_string', 'server_ip_string' +); $client->GET("https://server_ip_string:port/upm-server/nbi/organizatio +n", $headers ); my $response = $client->responseContent(); print $response;
IO::Compress::Gzip file close issues
2 direct replies — Read more / Contribute
by Paul.Unix
on Jul 26, 2016 at 07:08
    I encountered an issue with IO::Compress::Gzip. After a successful gzip I want to unlink the original file but sometimes the unlink fails with a "permission denied" I made a pragmatic work around by adding a delay and try the unlink again. But a good solution would be preferred. The same issue happens with moving the new .gz to another directory. The files are not in use by another process. Running Strawberry Perl 5.22.0 on Windows 2008 and 2012
    use warnings; use strict; use POSIX; use Cwd; use Cwd 'abs_path'; use Time::Local 'timelocal_nocheck'; # used for SCHEDULE option in +the MQX.ini use Net::Domain qw(hostname hostfqdn hostdomain domainname); use File::Basename; use File::Copy; use IO::Compress::Gzip qw(gzip $GzipError) ; use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; # module used in the state messages use Digest::MD5; # modules used in put mode use threads; use threads::shared; use Thread::Queue; if ( gzip $archfile => "$archfile.gz", AutoClose => 1, BinModeI +n => 1 ) { my $delete_try_counter = mqx_get_setting('ARCHIVEMOVETRY'); while ( -f $archfile and not unlink $archfile and $dele +te_try_counter != 0 ) { $global_EVENTLOG_IN_LQ->enqueue("WARNING, $arch_ha +shref->{'EVENTLOG'},Can not delete $archfile. Error: $! try: $delete_ +try_counter"); $delete_try_counter -= 1; sleep(mqx_get_setting('ARCHIVEMOVEWAIT')); # wait x sec +onds before retrying } $archfile .= ".gz"; # add .gz to the file name } else { # if the gzip failed try to arc +hive the original file $global_EVENTLOG_IN_LQ->enqueue("ERROR, $arch_hashref->{' +EVENTLOG'}, gzip failed on $archfile\n$GzipError"); }
print all files is soo slow! Why?
4 direct replies — Read more / Contribute
by harangzsolt33
on Jul 25, 2016 at 21:30

    I want to write a simple perl program that goes through the current folder recursively and looks at each item, if it's a file, print its contents and moves on to the next one.

    I am a beginner Perl programmer, and I don't know why this is happening, but this perl program stops responding, and then I have to kill it every time.

    I am using TinyPerl 5.8 under Windows 7.

    I am testing this program in a folder that has about 50 text files and no folders. When I launch my perl program, it seems to work perfectly fine, but it doesn't go back to command prompt. It just hangs. The cursor stops blinking, and I have to kill the process.

    If I only read the first 100 bytes of each file, then there's no issue. I am back to command prompt immediately. If I read the first 2000 bytes, then there's a 3-second delay. And I tried reading the entire file and print the content, but then after executing the script, it stopped responding and I had to kill it.

    use strict; use warnings; my $PATH = '.'; my $CONTENT; explore($PATH); sub explore { my $PATH = shift; my $FILE; my $SUB; opendir(my $DIR, $PATH) or return; while (my $SUB = readdir $DIR) { next if $SUB eq '.' or $SUB eq '..'; $SUB = "$PATH/$SUB"; # If it's a folder, explore it. # If it's a file, print it. if (-d $SUB) { explore($SUB); next; } if (-f $SUB) { open($FILE, '<:raw', $SUB) or next; read($FILE, $CONTENT, 2000) or next; close($FILE); print $CONTENT; $CONTENT = ''; # don't need this data anymore } } close $DIR; }
@INC not set for perlbrew
4 direct replies — Read more / Contribute
by Alessandro
on Jul 25, 2016 at 14:07

    Hi monks,

    I am on os x El capitan and have perlbrew installed. However, when I install a perl module I can't get it working, because it seems perl is not looking at the right place.

    Can't locate WWW/ in @INC (you may need to install the WWW::Mechanize module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2/darwin-thread-multi-2level /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .)


     which perl returns  /opt/local/bin/perl5

    my understanding is that it should return the path to perlbrew install and not the system perl.

    and  perl -v returns  This is perl 5, version 22, subversion 2 (v5.22.2) built for darwin-thread-multi-2level and I indeed used perlbrew to install and switch to perl 5.22.2 but it seems somehow, the "switch" was only partial. What am I missing here?


Recommendations on a module for web crawling
1 direct reply — Read more / Contribute
by edimusrex
on Jul 25, 2016 at 13:59

    I am trying to crawl a web page where the data I am seeking is generated by javascript. I haven't had to deal with this before but I can imagine I am not the only one who has come across this. Is there a specific module that is preferred in this instance? I've tried using Mechanize::Firefox but the page complains about unsupported browser. I'd prefer to do this in perl but will use other languages if need be.

    Thanks for your recommendations

New Cool Uses for Perl
Perl 6 SDL2 game
No replies — Read more | Post response
by holyghost
on Jul 25, 2016 at 02:04
    I need to have something to make a buffer for C32 byte arrays. This is for the SDL2 texture. I choose an Xpm file, as it faster parsable in perl. Buffer filling and swapping from a png package is less expensive, therefor I started a PNGImageObject. With PERL 6, SDL2::Raw panda package you can make the following perliminary game :
New Perl Poetry
Posthumous Apologies to Edgar Allen Poe
No replies — Read more | Post response
by perldigious
on Jul 30, 2016 at 19:12

    This reads best alongside an actual copy of "The Raven" since I tried pretty hard to match that as closely as possible whenever possible.

    The XP Whore

    Once I posed a desperate query, to my friends, at the monastery,
    Over many a terse and confusing page of perldoc bore—
         While I scolded, nearly snapping, my sanity at least slightly cracking,
    Perhaps I messed up the mapping, is the mapping to my @array poor?
    “Tis surely this,” I sputtered, “the mapping to my @array is poor—
              Thankfully answered by an XP Whore.”
         Ah, so fondly I remember when I became a PerlMonks member;
    And in my innocence never posted purely to be an XP Whore.
         Happily your code I’d borrow;—and back again I’d be tomorrow
         Though some examples left me harrowed—harrowed and synapses sore—
    For my ignorance was abundant and my knowledge of the language poor—
              But now I’m just an XP Whore.
         And the sunken, sad, depressed feeling from this realization
    Killed me—instilled me with monastic penance in hope to even the score;
         So that now, to still the clicking of my keyboard, I sat chanting
         “Laziness, impatience, and hubris be yours even more—
    May laziness, impatience, and hubris be yours even more;—
              But I’m still an XP Whore.”
         With each day my code grew stronger; although I am no Perl Monger,
    “Saints,” say I, “or simple Monks, it’s your wisdom I implore;
         But the fact is I’ve been sinning, and so openly you’ve been giving,
         And so prolifically you’ve been helping, helping this lowly XP Whore,
    That ashamed I am before you”—I admit I am an XP Whore;—
              Please ++ this $XP_Whore.
         At the XP levels I was peering, long I starred, my brain whirring,
    Pouting, scheming schemes to Sainthood that would be ill-gotten for sure;
         But the truth was awoken, that my soul would be broken,
         And the only words spoken by my conscience would be, “XP Whore.”
    This it repeated, with an echo in my console, “XP Whore!”
              I’m just a dirty XP Whore.
         Back to the monastery yearning, all my daily votes returning,
    Once again allowing me to ++ where I was unable before.
         “Certainly,” said I, “certainly this participation is monastic penance;
         Let me see, then, what this post is, and perhaps add more—
    Let me think clearly a moment and perhaps add more;—
              Because I am an XP Whore!”
         On this point I do not stutter, though, I often ramble and mutter,
    When the words sought in my brain are too deeply buried in its core;
         Or when a witticism fails me; or a Python Zealot flames me;
         But, from the wisdom of Erudil, nobody profits from a flame war—
    Even I know this truth that nobody profits from a flame war—
              Even I, a sinner, an XP Whore.
    Then my XP Nodelet chiming me from my philosophizing,
    By the wonderful and sought after fake internet points it bore,
    “Though thy value is argued in this Perl haven, thou,” I said, “art surely crave-en,
    Desired and coveted fake internet points of which I want more—
    Tell me what I must do to acquire even more!”
              Because I’m such an XP Whore.
         Much I’ve parsed this monastery to find wisdom given out so freely,
    Though its answers a little perplexing—a little ignorance it wouldn’t abhor;
         For we cannot help seeing that no unsaintly being
         Ever yet was not blessed with learning about Perl more—
    Links or heaps of code examples learned them Perl more,
              Thanks to my fellow “XP Whores.”
         But the Novice, sitting bewildered at his office, posts often
    That one thing, that the monks here so universally abhor.
         Incomplete code with inconsistent clutter—no use strict; or use warnings; uttered—
         Till the first monasterian mutters “Make sure your code runs before—
    Ignorant of our ways you may be, so Make sure your code runs before.”
              It’s hard to be an “XP Whore.”
         Embarrassed by this curtness spoken in reply to his post broken,
    “Apologies,” says he, “I’m simply new to learning Perl lore
         Caught by some unhappy manager who I fear could be a career damager
         Forcing fast and forcing faster maintenance on Perl code of yore—
    My experience has known none such Perl code of yore
              Please help me ‘XP Whores’.”
         But the monks still wondering what the Novice is pondering,
    Must wait for code and question clear, before knowledge pour;
         Then, with revision making, the Novice responsibility taking
         Kludge upon kludge, raking through his code so obviously poor—
    Receives fixes, suggestions, links, follow ups, and praises despite his code so obviously poor
              It’s what we do as “XP Whores.”
         Thus I sit engaged in confessing, but with little remorse expressing
    To the monks whose vast wisdom has engrained into my brain’s core;
         This and more I sit opining, with my thoughts all aligning
         On the subject of my rhyming that I’ll blatantly state once more,
    But that may be met with whining when I blatantly state once more,
              We are, all, just XP Whores.
         Now, methinks, many an XP dispenser, will ++ this if it passes the censor
    Swung by NodeReaper whose reaped-nodes frequent the Worst Nodes store.
         “Death,” I decree, “the gods hath given thee—a power that’s most unhol-ee
         Despite—despite the frequent ribaldry in the use of the word Whore;
    Quash, oh quash the use of your cruel scythe and accept this usage of Whore!”
              For the description fits “XP Whore.”
         “NodeReaper!” say I, “thing of necessary evil!—reaper still, if death or devil!—
    Whether Hater sent, or whether administrative duties brought thee to my door,
         I beseech to not be haunted, in this node that I have planted—
         Leave it to be freely taunted—this of you, I implore—
    Is there—is there need to plead?—tell me—tell me, I implore!”
              Please let me be an “XP Whore.”
         “NodeReaper!” say I, “thing of necessary evil!—reaper still, if death or devil!
    By the Saints that guide us—by the gods we both adore—
         Tell this sinner with hubris abundant, and yes Poe was a little redundant,
         If his post is destined to be cast upon the Reaper’s floor—
    His post of toiling labor cast upon the Reaper’s floor.”
              Please don’t squash this “XP Whore.”
         “Know this of the title you’re imparting, monk or novice!” I declare, ego guarding—
    “Also thee can be labeled with the title of XP Whore!
         Declare no hypocrisy by being outspoken unless thy intent is mutual joke-en!
         Just simply give your ++ token!—especially if the receiver is XP poor!
    Spare thy -- from their stats—especially if they’re XP poor!”
              Now kindly ++ this $XP_Whore.
         My goal here, which is fitting, is XP getting, is XP getting
    And if I have entertained you and brought you from a state of bore;
         My whimsical XP scheming toward that Sainthood I am dreaming,
         Having lifted your spirit more inside this monastery we adore;
    And my spirit lifted with it inside this monastery we all adore
              Then ++ this—$XP_Whore!

    I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
    I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious
New Obfuscated Code
Self-constructing Japh
No replies — Read more | Post response
by golux
on Jul 30, 2016 at 17:37
    It's been a while. Here's an obfuscated script written over 4 years ago that finally got finished up. Though it technically works in Windows with "perl -MWin32::Console::ANSI <script>", it looks much better in Linux or MacOS (or probably Cygwin), for which it was designed, as it uses ansi escape sequences.

    Note: to change the speed give an optional delay argument in fractions of a second. The default is 0.1 (ie. 0.5 would be slower, 0.05 faster).

    die+eval(q{$|=pr int"\e[ 2J\n";$k=' |';s ,,2 220;3500731;352273 5071;16007150 74;1622713,x;y; 0-4;8| _/%;;s ;5;\e[103m;g;s,6, \e[102m,g;s;7;\e [m;g;$/=$_;$_=q| hb2Gbb 5hhDei 4dh0Bh lFbi20 1hoC4d o0CdsB bp201h vDev5d v0ChzG |;s;[1 -9];>$&;g;s;[A-I ];^$&;g;y|A-I|1- 9|;{s;^(\w)(\w); ;x?($y =-97+ord$1,$x=-9 7+ord$2):s,^0,, ?$k='/':s,^([>^] )(\d), ,?map{$c=$1,$X=1 +3*$x,$Y=$y* 2,$Z=4;$"=$/=~s; %;$k;r ;map{p rint"\ e[${\$Y ++};${ X}H$_" ;$X--if++$ Z<7}sp lit';' ,$";$k= '|';se lect$J ,$a,$p,$ARG V[0]|| .1;'^' eq$c?$y --:$x+ +}1..$ 2:last;redo }}=~y %8 \n % %dr), "\e[". "22H\n"
    say  substr+lc crypt(qw $i3 SI$),4,5
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 having an uproarious good time at the Monastery: (4)
As of 2016-07-31 03:45 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (269 votes). Check out past polls.