Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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
missing values when using Parallel::ForkManager
1 direct reply — Read more / Contribute
by plagent
on Jul 03, 2015 at 01:51
    I used Parallel::ForkManager to scan the motifs in DNA string pairs. The script is the following:
    foreach my $id (1..100) { PWM: for my $pwm (@ciona_pwm_array) { $pm->start and next PWM; ($count) = count_pwm_num($pwm,$seq_1,$seq_2); $pm->finish; } $pm->wait_all_children; }
    There are three parameters for the function count_pwm_num. The first one is $pwm, which is from list @ciona_pwm_array and is the motif feature. The second and third are DNA strings. The function is to calculate the motif number (how many?)using motif feature $pwm in the DNA strings. The aim of the function count_pwm_num is to report the motif number from both strings. The following table is the report from the program. However, I calculated the same DNA strings 100 times ( the first for-loop) and used same motif list (@ciona_pwm_array, the second for-loop), there is always missed motif(s) in the report. For example, row a (first row), the program reported all six motif number from A-F. row b missed the number of the motif A (because they were same DNA strings, the output should keep the same). row c missed the number of motif B.row d missed the number for motif A and B. It seemed the missed motif numbers were randomly selected. So my question is: why count_pwm_num randomly skip some $pwm and do not perform the function of count_pwm_num?

    program result table:

    id	A	B	C	D	E	F
    a	1	1	0	1	1	0
    b		1	0	1	1	0
    c	1		0	1	1	0
    d			0	1	1	0
    e	1	1	0	1	1	0
    ..
    
    Expected result
    
    id	A	B	C	D	E	F
    a	1	1	0	1	1	0
    b	1	1	0	1	1	0
    c	1	1	0	1	1	0
    d	1	1	0	1	1	0
    e	1	1	0	1	1	0
    ..
    
Max of 23 and 27 is 23?
6 direct replies — Read more / Contribute
by luxgladius
on Jul 02, 2015 at 13:35
    Here's the output of an actual debug session. Can anybody explain this?
    DB<10> p $#l 27 DB<11> p $#F 23 DB<12> p max($#l, $#F) 23 DB<13> p max(27,23) 27 DB<14> p 0+$#l 27 DB<15> p max(0+$#l, $#F) 27 DB<16> p max($#l, 0+$#F) 23
    So the second-to-last line tells me the solution, but I have no clue what the actual problem is. For what it's worth, I'm using 64-bit Activestate Perl 5.20.

    Edit: The max is from List::Util.

Hang on STDOUT
2 direct replies — Read more / Contribute
by DanEllison
on Jul 02, 2015 at 08:55

    I'm using Strawberry Perl in a Windows 8 environment. I have a scheduler I have written in Perl that I have been using for a couple of years. Its a threaded application that runs more than 1500 jobs every night, so its doing a lot of the same thing over and over.

    The main engine spawns worker threads to run the individual jobs and reports some progress to STDOUT. I have had issues in the past where STDOUT would somehow get corrupted and the engine would stop reporting progress but continue to run and I would eventually find my progress messages in one of the job log files.

    I haven't seen that issue in a while, but lately I find the engine has simply hung. It writes messages to both STDOUT and to a log file, and I've been adding debugging left and right, and it simply appears to be hanging on prints to STDOUT.

    Autoflush is on and I can see single character updates, but here's an example:

    sub message { if ($options{verbose} && $options{verbose} >= ($_[1] || 0)) { if ($inprogress) { print "\n"; $inprogress = 0; } print "<"; my @time = localtime; print ">"; printf "%04d-%02d-%02d %02d:%02d:%02d %s\n", $time[5] + 1900, $time[4] + 1, $time[3], $time[2], $time[1], $time[0], $_[0]; } }
    $_[0] is the message I want to print. I thought maybe I was hanging trying to get the local time, but no. I put the < and > prints on either side of the localtime, but it hung between the > and the printf of the message.

    Has anyone had experience with this?

Make sin wave with GD
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 01, 2015 at 12:59
    Hi. I using GD package to make wave. But it does not work.
    use GD::Simple;
    $i = GD::Simple->new(400,400);
    ($x1,$y1) = (0,0);
    for ($x2=0; $x2<=400; $x2+=10) {
        $y2 = sin($x2)*400;
        $i->moveTo($x1,$y1);
        $i->lineTo($x2,$y2);
        ($x1,$y1) = ($x2,$y2);
    }
    print $i->png;
    
    How do I get right value for y2? Thank.
Win32::API in perl v5.20.2
5 direct replies — Read more / Contribute
by BillKSmith
on Jul 01, 2015 at 11:43
    I recently upgraded from Active State Perl 5.16.2 to 5.20.2 on my Win7 (64-bit) system. Most went well except for one script (which had been in daily use for a few years. It now fails with the message:
    Can't locate object method "new" via package "Win32::API" at C:\USERS\ +BILL\PERL\ LIB/PDFPrint.pm line 15.

    I have attached the module PDFPrint.pm referenced by the message. The code originally came from a post (http://www.perlmonks.org/?node_id=824842) in this forum

    Notes: In the install procedure, I saved and restored the ppm module configuration with ppm profile save/restore. While attempting to diagnose the problem, I noticed that a newer version of Win32::API was available on ppm. Installing the newer version did not change the result at all.

    Would someone please suggest a way to resolve this issue.

    I also have an unrelated issue with this “upgrade” because ActiveState has removed Perl/Tk from their ppm repository.

    Bill
Testing a .pl script
5 direct replies — Read more / Contribute
by perl_help26
on Jul 01, 2015 at 10:26
    Hello,

    I have a .pl script with the following structure:

    use X; use Data::Dumper; sub func1 {....} sub func2 {....} until (should_stop()) { ..... .... .. }
    I am trying to build a test module for this pl script. Is there a way to export the functions WITHOUT running the while loop? Preferably, I do not want to split the functions into a .pm file. Thanks ...
wild cards in Vertica
3 direct replies — Read more / Contribute
by pragov
on Jun 30, 2015 at 14:00
    Hi All,

    I have a perl-Vertica question. I need to pass a combination of a wild card and complete value of a field. It will be a combination of prefix and others. The example is ('A','BCD-UT1','MDO-CT1'). The actual value of A is ABC-EF2.But users can just click on Prefix,A to get all values starting with A. I tried,

    if ($clnm ne ""){ $cnt = @parts = split(/\,/, $ clnm ); $clnm = "'"; for ($i = 0; $i < $cnt; $i++) { $clnm = $clnm . $parts[$i]; ($clnm = $clnm . "%','") if ($i < $cnt - 1); } $clnm = $clnm . "%'"; } and then used it in if ($clnm ne "") { $Where = $Where . "AND m.CLNAME LIKE $clnm %’ OR m. +CLNAME IN ($clnm ) "; }.

    It is not working. The SQL either takes LIKE('A%') or IN ('ABC-EF2','BCD-UT1','MDO-CT1'), but not the combination. How to retrieve the value,('A','BCD-UT1','MDO-CT1')?

    Thanks, pragov
Get the number of the current test when debugging a test script
4 direct replies — Read more / Contribute
by Dumu
on Jun 30, 2015 at 07:00

    I'm testing a module I'm developing.

    To run the module, I have a test script which initialises the module.

    e.g.:
    • tests.t
    • module.pm

    There's a bug in the module that is causing the test to fail after a certain test number.

    I'd like to run the test using the Perl debugger perl5db.pl and break after the nth test. Is there a way to monitor the variable showing how many tests have been run?

    Test::Builder has a $current_test package variable but I can't seem to access it. I'm using Test::Most.

Perl Scripts Terminates unexpectedly
2 direct replies — Read more / Contribute
by gvbals
on Jun 30, 2015 at 02:13
    We have a set of perl scripts. We don't have any exception handling. Sometime the scripts terminates unexpectedly. How to find out the reason for the same/
FOSDEM 2015 - any news on the party?
2 direct replies — Read more / Contribute
by polettix
on Jun 29, 2015 at 17:52
    Hi,

    since when it happened, I'm regularly checking the FOSDEM website for the video of the talk from Larry Wall "get ready to party". It's a bit depressing that so far nothing appeared, and that of all the "main tracks" the one on languages - where the talk should appear - is still empty. I'm using this link: https://video.fosdem.org/2015/.

    Does anyone know if there is some not-so-evident reason that is preventing the release of those videos? Is it just that I need to have some little more patience?

    Thanks, Flavio.

    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Io ho capito... ma tu che hai detto?
Installing Module::Info 0.35 for Strawberry Perl 5.22.0
2 direct replies — Read more / Contribute
by Athanasius
on Jun 28, 2015 at 11:50

    Background. I’ve started using Strawberry Perl 5.22.0, and I’m trying to install tobyink’s useful P5U module. It has various dependencies, one of which fails to install: Module::Info, which fails 2/7 tests, 11/121 subtests. From the CPAN Testers Matrix it appears that Module::Info has failed almost universally across all platforms since Perl version 5.21.2. But are these failures serious or trivial? I decided to investigate.

    Many of the failures are traceable to the Subroutine B::OP::parent redefined warning which appears to be a known problem. The tests fail in two test modules:

    • t/Module-Info.t (10/59)
    • t/n1_modules.t (1/3)

    It is the single test failure in the second of these modules that is currently puzzling me.

    The problem. The subtest which fails in t/n1_modules.t is this:

    is_deeply( [ sort keys %mods ], [ sort qw(Cwd strict Carp) ], "Got the correct modules" );

    It fails as follows:

    # Failed test (t\n1_modules_required.t at line 17) # Structures begin differing at: # $got->[2] = 'Win32' # $expected->[2] = 'strict' # Looks like you failed 1 tests of 3. t\n1_modules_required.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/3 subtests

    This failing subtest is supposed to verify that the 3 listed modules are used or required by the test module t/lib/Bar.pm. Here are the full contents of that module:

    package Bar; use Cwd; use Cwd 1; use Cwd 1.00102; use Cwd 1.1.2; BEGIN { cwd(); } BEGIN { $x = 1; $x = 2; require strict; } sub my_croak { require Carp; Carp::croak(cwd, @_); } 1;

    It has 24 lines. I have used a hex editor to confirm that there is nothing extra “lurking” in the file — WYSIWYG. Note that there is no mention of the Win32 module in Bar.pm.

    The labyrinth. The route taken by the chain of subroutine calls from the failing test back to the source of the discrepency is a tortuous one (for ease of reading I have replaced the full paths with ellipses):

    1. The failing subtest on line 14 of t/n1_modules_required.t compares a list of modules found against a list of expected modules. Since these are the modules used or required by t/lib/Bar.pm, the expected modules are (naturally) Cwd, strict, and Carp. The modules are found via the following calls:

      my $bar = Module::Info->new_from_module( 'Bar' ); ... my %mods = $bar->modules_required;
    2. Module::Info->new_from_module calls Module::Info->_find_all_installed, which returns this object:

      bless({ dir => "...\\t\\lib", file => "...\\t\\lib\\Bar.pm", name => "Bar", safe => 0, use_version => 0, }, "Module::Info")
    3. The call to Module::Info->modules_required gets a list of modules via the following call:

      my @mods = $self->_call_B('modules_used');
    4. _call_B in turn calls my($status, @out) = $self->_call_perl($command); with $command set to:

      "-MO=Module::Info,modules_used" "...\t\lib\Bar.pm"
    5. _call_perl calls @out = `$command 2>&1`; with $command set to:

      ...\perl\bin\perl.exe "-MO=Module::Info,modules_used" "...\t\lib\Bar. +pm"

    The anomalies. Now, here’s where things get weird. First, we seem to have entered an infinite regression: modules_required calls _call_B, which calls _call_perl, which (apparently) calls modules_used. But modules_used calls modules_required, so we seem to be back where we started. But there is no infinite regression, so that can’t be what’s happening. Ok, so what does the call to:

    ...\perl\bin\perl.exe "-MO=Module::Info,modules_used" "...\t\lib\Bar. +pm"

    actually do?

    Second, that last call returns the following data:

    Subroutine B::OP::parent redefined at ...\blib\lib/B/BUtils.pm line 21 +7. , use Cwd () at "...\t\lib\Bar.pm" line 3 , use Cwd (1) at "...\t\lib\Bar.pm" line 4 , use Cwd (1.00102) at "...\t\lib\Bar.pm" line 5 , use Cwd (v1.1.2) at "...\t\lib\Bar.pm" line 6 , use Win32 (0.27) at "...\t\lib\Bar.pm" line 624 , require bare strict.pm at line 15 , require bare Carp.pm at line 19 , ...\t\lib\Bar.pm syntax OK

    Note that the Win32 module is reported as being used on line 624 of file Bar.pm. Not only does that file contain no mention of Win32; but it’s only 24 lines long! How does the call find an unmentioned module on a non-existent line of code?

    I previously installed the same version (0.35) of Module::Info under Strawberry Perl 5.20.2, with no errors.

    The questions. Can anyone shed any light on any of this? Suggest a way to carry the researches forward? Explain what happened between 5.20.2 and 5.22.0 to account for this bizarre behaviour? Assure me that force installing Module::Info will be safe?

    Anyway, thanks for looking, :-)

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

New Meditations
The problem of documenting complex modules.
No replies — Read more | Post response
by BrowserUk
on Jul 05, 2015 at 04:41

    This is meditation; but I also hope that it might start a discussion that will come up with (an) answers to what I see as an ongoing and prevalent problem.

    This has been triggered at this time by my experience of trying to wrap my brain around a particular complex module; but I don't want to get into discussion particular to that module, so I won't be naming it.

    Suffice to say that CPAN is replete with modules that are technically brilliant and very powerful solutions to the problems they address; and that deserve far wider usage than they get.

    In many cases the problem is not that they lack documentation -- often quite the opposite -- but more that they don't have a simple in; a clearly defined and obvious starting point that gives a universal starting point on which the new user can build.

    And example of (IMO) good documentation is Parallel::ForkManager. It's synopsis (I've tweaked it slightly to remove a piece of unnecessary fluff):

    use Parallel::ForkManager; my $pm = Parallel::ForkManager->new($MAX_PROCESSES); foreach my $data (@all_data) { # Forks and returns the pid for the child: my $pid = $pm->start and next; ... do some work with $data in the child process ... $pm->finish; # Terminates the child process }

    is sufficient to allow almost anyone needing to use it, for almost any purpose, to put together a reasonable working prototype in a dozen lines of code without reading further into the documentation.

    As such, it allows the programmer to get started and move forward almost immediately on solving his problem -- which isn't "How to use P::FM" -- and only refer back to and utilise the more sophisticated elements of P::FM, as and when he encounters the limitations of that simple starting point.

    As such, the module is successful in hiding the nitty-gritty details of using fork correctly; whilst imposing the minimum of either up-front learning curve or infrastructural boiler-plate upon the programmer; who has other more important (to him) things on his mind.

    Contrast that with something like POE which requires a month of reading through the synopsis of the 800+ modules in that namespace POE::*, and then another month of planning, before the new user could put together his first line of code. As powerful as that module, suite of modules; dynasty of modules is, unless you have the author's help, and lots of time, getting started is an extremely daunting process. In that respect (alone perhaps), POE fails to enable a 'simple in'.

    And before anyone says that it is unfair to compare those two modules -- which maybe true -- the purpose was to pick extremes to make a point; not to promote or denigrate either.

    Another module that I know I should have made much more use of in the type of code I frequently find myself writing, is PDL. I've tried at least a dozen times to use PDL as a part of one of my programs; and (almost) every time I've abandoned the attempt before ever writing a single line of PDL, because I get frustrated by the total lack of a clear entry point in to the surfeit of documentation.

    There's the FAQ, and the Core; and the Index; and the QuickStart; and the Doc; and the Basic; and the Lite; and the Course; and the Philosophy; and the pdldoc; and the Tips; and ... I'm outta here. I'm trying to write my program, which does a little math on some biggish datasets that would benefit from being vectored, but life's too short...

    Again; the underlaying code is brilliant (I am assured), and it isn't a case of a lack of documentation; just a mindset that says: "this is PDL in all its glory, power and nuance. bathe yourself in its wonderfulness and wallow in its depth". Oh, and then when you've immersed yourself in its glory, understood its philosophy, and acclimated its nuance, then you can get back to working out how to use it to solve your problem.

    And that's a real shame; and a waste.

    I'm not sure what the solution is. I do know that the modules I use most List::Util, Data::Dump, threads etc. I have rarely ever had to look at the documentation; their functionality has (for me) become an almost invisible extension of Perl itself, and only the occasional (perhaps you forgot to load "sum"?) reminds me that they aren't.

    Of course, what they do is essentially pretty simple; but that in itself is a perhaps a clue.

    I do know that (for me) the single most important thing in encouraging my use of a module is being able to C&P the synopsis into my existing program, tweak the variable names, and have it do soemthing useful immediately.

    In part, that comes down to a well designed API; in part, to well-chosen defaults; and part having a well-chosen, well-written synopsis that addresses the common case; with variable names and structure that make it obvious how to adapt that synopsis for the common case. Once I have something that compiles and runs -- even if it doesn't do exactly what I need it to do; or even what I thought it would do from first reading -- it gives me a starting point and something to build on. And that encourages me to persist. To read the documentation on a as-I-need-to basis to solve particular problems as I encounter them.

    Over a decade ago, I posted My number 1 tip for developers.; and this is the other side of that same philosophy. Start simple and build.

    And that I think has to be the correct approach to documenting complex modules. They need to:

    1. Offer a single, obvious, starting point. The in.
    2. That needs to be very light on history, philosophy, jargon, technical and social commentary and background. And choice.
    3. It needs to offer a single, simple, well-chosen, starting point, that requires minimal reading to adapt to the users code, for the common case.
    4. It then needs to offer them a quick, clear, simple path to solving their problem.

    What it must not do:

    • It mustn't present them with 'a bloody great big list of entrypoints/methods'.
    • It mustn't offer them a myriad of choices and configuration options.
    • It mustn't take them on a deep immersion in the details of either algorithms or implementation.
    • It mustn't present them with either "Ain't this amazing" nor "Ain't I clever" advert.
    • It mustn't waste their time with details of your personal preferences, prejudices, philosophies and theologies.

    If you want programmers to use your modules, you need to tell them what (the minimum) they *NEED TO KNOW* to get started. And then give a clear index to the variations, configurations and extension to that basic starting point.

    Achieve that, give them their 'in', with the minimum of words, fuss or choice, and they come back for all the rest as they need it.


    This is ill-thought through and incomplete, so what (beyond risking offending half the authors on CPAN) am I trying to achieve with this meditation?

    I'd like to hear if you agree with me? Or how you differ. What you look for in module documentation. Examples that you find particularly good; or bad.

    It'd be nice to be able to derive from the thread, a set of consensus guidelines to documenting moderate to complex modules -- that almost certainly won't happen -- but if we managed to get a good cross section of opinions on what makes for good and bad documentation; and a variety of opinions of the right way to go about it; it might provide a starting point for people needing to do this in the future.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
RFC: Net::SNTP::Client v1
3 direct replies — Read more / Contribute
by thanos1983
on Jun 30, 2015 at 12:45

    Hello Everyone,

    About a year ago I started with the idea of creating a Perl module based on Net::NTP. The module that I am thinking to create would be named (Net::SNTP::Client). The difference between those two is the precision, from my point of view the Net::NTP module does not get correct millisecond/nanosecond precision. The module is based on RFC4330, where according to the RFC different precision will achieved on LinuxOS and WindowsOS.

    In theory the module should be compatible with all OS (WindowsOS, LinuxOS and MacOS) please verify that with me since I only have LinuxOS.

    I am planning to create also another module Net::SNTP::Server which is approximately an SNTP server and when I say approximately is because I can not figure it out how to replicate the server side. But any way first thing first.

    Is it possible to take a look and assist me in possible improvements and comments. Since this is my first module I have no experience so maybe the module is not well written.

    The execution of the script is very simple, create a script e.g. client.pl and put the code bellow.

    client.pl

    I have inserted four options:

    -hostname => NTP Hostname or NTP IP -port => 123 Default or Users choice e.g. 5000 -RFC4330 => 1 -clearScreen => 1

    The first option is to get an RFC4330 printout way, and the second option is to clear the screen before the printout. I think both options will be useful on the printout of the script.

    I have chosen to paste the module in the folder path "/home/username/Desktop/SNTP_Module/Net/SNTP/Client.pl". Remember for testing purposes to change the path on client.pl accordingly on the location that you will place the module.

    Update 1: Removing (EXPORT_OK, EXPORT_TAGS, shebang line) based on toolic comments.

    Update 2: Removing $frac2bin unused sub.

    Update 3: Adding some checks on the input of getSNTPTime sub

    Update 4: Adding Plain Old Documentation format and updating code based on Monk::Thomas comments.

    Update 5: Updating code based on Monk::Thomas new comments.

    Net::SNTP::Client.pm

    Thank you for your time and effort reading and replying to my question/review.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
New Cool Uses for Perl
Syntax-highlight Non-Perl Code for HTML
1 direct reply — Read more / Contribute
by kcott
on Jun 29, 2015 at 01:19

    G'day All,

    I use a scripting language, called NWScript, for some CRPG development that I do from time to time.

    I wrote the following Perl script to syntax-highlight NWScript code for HTML rendering:

    #!/usr/bin/env perl use 5.014; use warnings; { my %entity_for = qw{& &amp; < &lt; > &gt;}; sub chars_to_ents { $_[0] =~ s/([&<>])/$entity_for{$1}/gr } } my @plain_captures = qw{white_space remainder}; my @highlight_captures = qw{operator variable function constant statem +ent datatype comment string integer float prag +ma}; my $re = qr{ (?> (?<white_space> \s+ ) | (?<comment> (?> \/\* (?: . (?! \*\/ ) )*+ (?: . (?= \*\/ ) )?+ \*\/ | \/\/ [^\n]* $ ) ) | (?<pragma> (?> [#]include \s+ " \w+ " \s* $ | [#]define \s+ \w+ \s+ \w+ \s* $ ) ) | (?<string> " (?: [^"\\]++ | \\. )*+ " ) | (?<float> \b \d+ \. \d+ f? \b ) | (?<integer> \b \d+ \b ) | (?<constant> \b [A-Z0-9_]+ \b ) | (?<datatype> \b (?> action | const | effect | event | float | int | itemproperty | location | object | string | struct \s+ \w+ | talent | vector | void ) \b ) | (?<statement> \b (?> break | continue | do | for | if | else | return | switch | case | default | while ) \b ) | (?<function> \b [A-Za-z_] \w* (?= \s*\( ) ) | (?<variable> \b [A-Za-z_] \w* \b ) | (?<operator> (?> \>\>\>\= | \>\>\> | \>\>\= | \<\<\= | \>\> | \<\< | \+ +\+ | \-\- | \&\= | \|\= | \^\= | \*\= | \/\= | \%\= | \+\= | \-\ += | \=\= | \!\= | \<\= | \>\= | \&\& | \|\| | \< | \> | \! | \& | \| | \^ | \~ | \* | \/ | \% | \+ + | \- | \= | \? | \: | \; | \. | \{ | \} | \( | \) | \, | \@ ) ) | (?<remainder> .*? ) ) }msx; my $init_code = do { local $/; <> }; say '<pre class="syntax-highlight">'; MATCH: while ($init_code =~ /$re/g) { for my $plain_capture (@plain_captures) { if (exists $+{$plain_capture}) { print $+{$plain_capture}; next MATCH; } } for my $highlight_capture (@highlight_captures) { if (exists $+{$highlight_capture}) { print '<span class="', $highlight_capture, '">', chars_to_ents($+{$highlight_capture}), '</span>'; next MATCH; } } } say '</pre>'; exit;

    NWScript uses a C-like syntax. I'm aware that a few monks use NWScript; however, I'd guess most don't and have probably never heard of it. So, purely to provide an example that's looks a little more familiar to most, here's a slightly fudged (just the #include pragma) hello.c:

    /* hello.c */ #include "stdio" main() { printf("hello, world\n"); }

    And here's the output after running that through my script:

    <pre class="syntax-highlight"> <span class="comment">/* hello.c */</span> <span class="pragma">#include "stdio" </span> <span class="function">main</span><span class="operator">(</span><span + class="operator">)</span> <span class="operator">{</span> <span class="function">printf</span><span class="operator">(</span +><span class="string">"hello, world\n"</span><span class="operator">) +</span><span class="operator">;</span> <span class="operator">}</span> </pre>

    For anyone wishing to use this script, here's the CSS I use (in the Spoiler):

    -- Ken

New Obfuscated Code
How not to do prime factorization
2 direct replies — Read more / Contribute
by thisisdada
on Jun 30, 2015 at 10:05
    $"x=$%="@ARGV";$~=$;='( +)';while($%>>$:++){if($"=~/$~$/^$"=~/$;$/){$ |=$?=$:>2||die"prime\n";eval"print length(\$$?)".($:>++$?&&"/length(\$ $?).'*'")while$:>$?;die$/}$;=$~;$~=~s~.*~^($&\\1+)~;$~=~s;\d+;1+$&;eg}

    The best thing I can say about this code is that it works. It will take a number via argv give you the prime factorization of that number... eventually. It's not very efficient. At all. I had a lot of fun writing it, but it's really bad at what it does. To give you an idea of how erratic it is, here are some benchmarks:

    While it can distinguish primes at a reasonable rate, it takes a really long time to factor composite numbers. Particularly composite numbers made up of several small primes. Powers of 2 are the worst-case scenario.

    for$b(-25..25){for$a(-50..29){$x=$a/21;$y=$b/15;print$b?chr:chr^chr ord(substr'<6C}'.1x29 .'[FDEq2?@E96Cqa6C=q924',$a)-49;$_=30;($y,$x) =(2*$x*$y+$b/15,$x*$x-$y*$y+$a/21)while$x*$x+$y*$y<9&$_++<95}$_=10}
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 examining the Monastery: (9)
As of 2015-07-05 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls