Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
"be consistent"
 
PerlMonks  

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
The 'eval "require $module; 1"' idiom
3 direct replies — Read more / Contribute
by sedusedan
on Apr 19, 2014 at 01:04

    Could someone refresh me on why the ; 1 part is necessary again? In other words, why is this idiom safer/better/more correct than just eval "require $module", especially in the context of using the expression in conditional (e.g.: eval "require $module; 1" or warn "Can't load $module";). I've used this idiom for years, and recently even submitted a patch to Log::Log4perl related to this. But for the love of heaven, I forgot why it's needed in the first place. Let's consider the cases:

    Case 1. Module cannot be not found on the filesystem. require dies with message "Can't locate $module in @INC ...", eval traps it and sets $@ and returns undef. ; 1 part in idiom is not needed (unreached).

    Case 1b. Like case 1, but previous attempt has been made. Ditto.

    Case 2. Module has compile errors. require dies with compile error message, eval traps it and sets $@ and returns undef. ; 1 part in idiom is not needed (unreached).

    Case 2b. Like case 2, but previous attempt has been made. After the first attempt, the entry in %INC is set to undef. At the second attempt, require will die with message "Attempt to reload $module aborted", eval traps it, sets $@, and returns undef. ; 1 part in idiom is not needed (unreached).

    Case 3. Module is loaded successfully and returns a true value (in other words, the normal success case). require will return 1. ; 1 part in idiom is not needed.

    Case 3b. Like Case 3, but previous loading has been made. require will return 1. ; 1 part in idiom is not needed.

    Case 4. Module is loaded successfully but returns a non-true value. require will die with message "$module did not return a true value ...". eval traps it, sets $@, and returns undef. ; 1 part in idiom is not needed (unreached).

    Case 4b. Like case 4, but previous attempt has been made. Ditto.

    There are other cases possible (like a permission error when reading source file, require() being overriden, etc) but the above are the common/majority cases. So what cases does the ; 1 part cover? Does this have something to do with older versions of perl (I'm testing this on 5.18.2).

Using 64 Bit Perl for Production Scripts.
9 direct replies — Read more / Contribute
by pmu
on Apr 18, 2014 at 08:31

    Respected Monks,

    We're going get a new set of SAN Management Servers and I am planning to install Strawberry Perl Version 5.18.2.2 (64 Bit) on it. I googled about it and found that its often recommended to stick to 32 Bit Perl eventhough the OS is 64 Bit because 64 bit versions of some Perl Modules have issues. Is that still the case or can I go ahead using 64 Bit Perl?

    Please let me know.

    -------------------------------------------------------------- Perspectum cognitio aeterna --------------------------------------------------------------
What are the advantages or disadvantages of "require" over "use"
8 direct replies — Read more / Contribute
by ghosh123
on Apr 18, 2014 at 01:57

    Hi ,
    I just wanted to know about the advantages and disadvantages of "require" over "use" in Perl.

    I know that :
    1. "use" is evaluated at compile time and "require" at run-time.
    2. If the module I am using with "use" has syntax error they will be thrown while compiling, on the contrary if the module is "require" ed then they will come during run-time and no errors will be reported in compile time.
    3. When we do "use", the control is passed to that file at run-time and whereas in case of "require" the code from that module/file is included to my code which is "require"ing it at run-time.
    4. If I have a module which does a lot in the BEGIN block and I don't really need it in all cases , then it is clever to "require" it so that I won't have to wait for all the initializations of that module in case I don't need it.

    My question is :
    is there any gain in terms of memory consumption when I use "require" or any other advantage ? Please let me know.
    Thanks.

Sockets, eval , and DIE
1 direct reply — Read more / Contribute
by Wiggins
on Apr 17, 2014 at 12:12
    I am looking for edge condition precedences. Syswrite to a closed socket(closed at remote end) results in Perl termination, with or without eval. Are there edge conditions that allow this?

    This code (without the eval and test blocks) can be seen on the botton of page 209 of Advance Perl Programming, #1. The MSG module.

    while (@$rq) { my $msg = $rq->[0]; my $bytes_to_write = length($msg) - $offset; my $bytes_written = 0; while ($bytes_to_write) { #write the prefixed length print "_send: syswrite to sock prefix length\n"; eval { $bytes_written = syswrite ($sock, $msg, $bytes_to_write, $offset); }; if ($@){ print "_send: syswrite to sock error <$@>\n"; } print "_send: syswrite to sock returned <$bytes_written>\n"; if (!defined($bytes_written)) { if (_err_will_block($!)) { # Should happen only in deferred mode. Record how # much we have already sent. $conn->{send_offset} = $offset; # Event handler should already be set, so we will # be called back eventually, and will resume sending return 1; ...
    This is Perl 5.14.
    The consistant result, running in foreground, when the server is shutdown, and a client send is attempted is:
    checkRealTTY:: starting UID=<UID> rIP=<> Acct=<root> _send entered <Msg=HASH(0x29987c8)> flush=<1> _send: syswrite to sock prefix length root@kali:/usr/share/msg/bin#

    It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Pre-pen testing code review
2 direct replies — Read more / Contribute
by tachyon-II
on Apr 17, 2014 at 12:01

    We have a reasonably well organised Catalyst MVC app that is about to undergo a code available pen test.

    I'm looking to get someone with an interest in the area to do a pre-pen test code review and would like any pointers the community has about good places to look, or specific people to ask.

    As well as the perl there is quite a bit of AJAX as well as iOS and Android apps that interfaces with the perl core.

install Devel::Cover 1.09
2 direct replies — Read more / Contribute
by perl_help26
on Apr 17, 2014 at 06:04
    I am trying to install an earlier version of Devel::Cover (i.e. Devel::Cover 1.09) how do I do that exactly? Thanks
Persistent HTTP connection
2 direct replies — Read more / Contribute
by mst226
on Apr 17, 2014 at 05:31
    Hi everyone.

    I am trying to write a web client that connects to an API using HTTP. The API server is the Gephi software (https://gephi.org) with the "streaming plugin" which accepts commands to modify a graph in real-time. My goal is to visualize Internet traffic showing end-stations as nodes and connections as edges.

    The API was not written by me and there is no way to change its behaviour. (There might be, but this is out of scope)

    This API is somehow special since the HTTP connection stays open the whole time (even if it is idle).

    So, my plan is to:
    1. make a http connection to the server
    2. send commands (POST) in JSON format using the established connection
    3. wait for a reply which might take a while
    4. send more commands
    5. wait for replies
    and so on.

    Only steps 1. and 2. are fixed. There is no order in the following steps. Some commands expect a reply while others do not. Also it is possible to send hundreds of commands without waiting for reply.

    I tried to build the web/api client using LWP and IO::Socket::INET, but the connection is closed at some point in time.

    Basically it is possible to open/close the connection for every single command, but this limits the performance of the web/api client.

    The API is described here:
    https://wiki.gephi.org/index.php/Graph_Streaming
    Is it focused on Java but on the bottom there are examples of the command syntax.

    Can you give me some hints how to continue?

    Thanks.
    -Markus
How to get the path coverage (or lines of code executed) after running a perl test file
2 direct replies — Read more / Contribute
by perl_help26
on Apr 16, 2014 at 11:11

    Hello Everyone, I wrote a test file using LWP::Simple. How can I know the path coverage of my test file or the lines of code being executed in my program? Is there an easy way? Preferably not with Devel::Cover since it just won't install using cpan!... (there's a test that's failing aeval_merge.t does anyone know why? Thank you...

Comparing results of math operations
8 direct replies — Read more / Contribute
by stangoesagain
on Apr 16, 2014 at 05:12
    Little real life problem
    #!/usr/bin/perl use strict; use warnings; use 5.010; my $x=0.95*806; my $y=1.3*589; say $x <=> $y; $x == $y ? say 'equal' : say $x.' '.$y; say $x cmp $y; $x eq $y ? say 'equal' : say $x.' '.$y; #now with simpler math $x=2*1.25; $y=5*0.5; say $x <=> $y; $x == $y ? say 'equal' : say $x.' '.$y; say $x cmp $y; $x eq $y ? say 'equal' : say $x.' '.$y;
    gives
    -1 765.7 765.7 0 equal 0 equal 0 equal
    Why? What's wrong?
better way to escape escapes
5 direct replies — Read more / Contribute
by RonW
on Apr 15, 2014 at 19:48
    I am processing an input format that can use either @ or \ to introduce inline directives. when a literal @ or \ is in the input, either character can be used to escape either character. IE: @@ or \@ or \\ or @\

    Currently, I replace the escape sequences with place holders, then extract directives, then replace the placeholders with the intended literal occurrences of @ and \ in the string.

    s/(?<![\\\@])[\\\@]\@/\x11/g; s/(?<![\\\@])[\\\@]\\/\x12/g; while (/[\\\@]([_A-Za-z]+)/) { print "Extracted code '$1'\n"; s/[\\\@]$1//; } s/\x11/\@/g; s/\x12/\\/g;

    I'm sure there's a better way, but my search-foo is lacking. And so is my regex-foo. (And there's likely an input file that will break this.)

    (and no, it's not LaTeX, despite the similarities)

Perl Directory file extension stats.
3 direct replies — Read more / Contribute
by sidsinha
on Apr 15, 2014 at 17:32
    Hi,

    I had a question regarding Perl directory statistics. Are there any perl packages that I can use to list the number of unique file extentions in a given directory?

    For ex, it should parse through an input directory (including subdir) and return the number of unique file types (for ex, 200 .bmp , 50 jpg ,20 txt) etc.


    Please guide me . thanks.
Lingua: Transform "wasn't" into "was not"
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 15, 2014 at 14:09

    Hello

    As the title suggests, I'm looking for a module which converts various English shortcuts like we're into we are, I'm into I am, etc...

    I couldn't find any module in CPAN which does this. Maybe I haven't looked for the right name.
    So my question is: did anyone worked with something similar before? What module would you recommend for doing this?

    Thanks

New Cool Uses for Perl
Perl Script to extract host list from Symmetrix DMX Array.
No replies — Read more | Post response
by pmu
on Apr 18, 2014 at 15:43

    Hi,

    As an Storage Administrator who works on EMC Symmetrix Storage Array, many times, I have to extract a list of all the hosts connected to the storage array. This needs to be extracted by logging into the storage array and running a command like symmask -sid 12345 list logins, and then the hostnames are to be extracted from the list and stored in a text file. If hostnames are not reflecting, then the corresponding World Wide Name (WWN) of the Host HBA should be included in the list. To ensure dual or quadruple redunduncy, each host will show two paths or four paths, so the duplicates need to be removed and the host names need to be in Upper case. There are many such arrays, and a seperate file needs to be created for each of them.

    Sometimes, the file has to be regenerated every few minutes due to some changes/requirements and the old file must be deleted, else wrong records will be captured. The script picks the array name from the command output stated earlier. This script is working fine on Redhat Linux 6.4 running Perl Version 5.10.1 and on Windows 2003 running Strawberry Perl version 5.18.2.2.

    Hoping fellow EMC Administrators will find this script useful. Please note - I dont get to write scripts on a regular basis, so there's quite a lot of improvement that can be done with the script. If so, kindly let me know. Here's the script:

    Here's the test file that's fed to the script. The actual file will have much more entries than what's given below.

    And here is the output:

    C:\Users\pmu\Documents\perl\work>perl hostnames.pl test_list_logins.tx +t Deleting existing "hostlist_hostnames.pl_000190101234.txt". A new one +will be created. ********************************************************************** +******************* Please Check the file - [ C:\Users\pmu\Documents\perl\work\hostlist_ho +stnames.pl_000190101234.txt ]. NULLs are replaced with corresponding pWWNs. ********************************************************************** +******************* C:\Users\pmu\Documents\perl\work

    And here's what the file - hostlist_hostnames.pl_000190101234.txt contains:

    -------------------------------------------------------------- Perspectum cognitio aeterna --------------------------------------------------------------
Sidef - The experimental scripting language written in Perl
No replies — Read more | Post response
by trizen
on Apr 17, 2014 at 09:28

    I remember that, a few years ago, someone asked a question about Writing a Programming Language in Perl. I was a little bit skeptical at first, but very interested in this subject too. Few years passed by, until me and a friend of mine decided to create a toy-language from scratch without using anything else, but Perl. We wanted it as simple as possible and powerful as much as it can be.

    Object-oriented paradigm must be the answer, right? We thought so. And it is, partially. The language we designed is called Sidef. It strongly follows the OO style; each piece of data is stored inside objects with own methods and operators defined to work on that type of data. (actually, in Sidef, an operator and a method are the same thing)

    Simplicity? What do we mean by something simple? How simple can a programming language be defined? This is the main question that I wanted to answer. A year after the start of the project, I think we found a reasonable answer: objects and methods. This is, I think, the simplest way a programming language can be defined. But, what about conditional expressions? They can't be created by objects and methods only, right? Wrong! They can:

    if (false) { } elsif (true) { } else { }
    is equivalent with:
    var condObj = if(false); # 'if' object condObj do { } elsif(true) do { } else { }
    What? Yes, the above code is valid code. if(expr) returns an object which accepts methods like 'do', 'elsif' and 'else'.
    This proves how flexible an OO language can be. The basic definition of Sidef is this: obj.method(obj), with minor exceptions.

    Objects are:
    • strings
    • files
    • numbers
    • arrays
    • everything else
    while methods are functions defined for that kind of object which returns other objects.

    In Sidef, the numbers have a very special purpose. We see the language as a toy-language and recommend to be seen only this way, but still it can be used in simple home-made projects, especially in those involving number computation. Numbers, by default, are represented by Math::BigFloat objects, giving them a better precision at the cost of being somewhat slower than Perl's standard representation for numbers (-Nfast).

    Perl related features:
    • any Sidef script can be compiled to a stand-alone Perl program (-c)
    • can load and use Perl modules (both OO and functional)
    • can evaluate arbitrary Perl code (Sys.eval(""))
    • supports memoization via Memoize (-M) (not enabled by default)
    • no CPAN module is required

    The project is available at: https://github.com/trizen/sidef
    The documentation page: https://github.com/trizen/sidef/wiki
    The RosettaCode page: http://rosettacode.org/wiki/Sidef

    The very basic concept of the language can be found at: https://github.com/trizen/sidef/blob/master/utils/sidef_concept.pl

New Monk Discussion
propose updating node about linking to cpan modules
4 direct replies — Read more / Contribute
by Lotus1
on Apr 16, 2014 at 11:34
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 rifling through the Monastery: (4)
As of 2014-04-19 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls