Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Perl Humor

by AcidHawk (Vicar)
on Sep 20, 2002 at 10:13 UTC ( [id://199426]=perlmeditation: print w/replies, xml ) Need Help??

HaHaHa,

In my quest recently to find a way of encrypting and decrypting a string in perl. I came accross this GEM of a web site Infrequently Asked Questions About Perl

I was searching for "perl string decrypt" and came across this page that has this

How do I decrypt a string that I encrypted with crypt()?

I thought I had struck gold. This is exactly what I had been looking for, for hours.

I looked at the code in his solution and thought ... jeesh I am going to need to concentrate on this.!..
This is what it looked like.

sub decrypt { my $c = shift; my @c = (0) x 8; for (;;) { my $i = 0; my $s = join '', map chr, @c; return $s if crypt($s, $c) eq $c; $c[$i]=0, $i++ while $c[$i] == 255; return undef if $i > 7; $c[$i]++; } }

A Warning even followed.

Warning: Exporting this function outside the USA may be illegal under the provisions of ITAR.

I loaded the code into my editor and as I was about to start I noticed the question below the one I was interested in,

How do I get my perl program to run faster?

use more 'cpu'; use less 'time'; use more 'speed';

No!!! It can't be... I have never seen those used before...

It was only then that I started to read the page from the begining...

My best is...

How do I get tomorrow's date?

Use this function:
sub tomorrow_date { sleep 86_400; return localtime(); }

There must be tons more of this stuff out there, as soon as I get a gap I am going to search for it.
-----
Of all the things I've lost in my life, its my mind I miss the most.

Replies are listed 'Best First'.
Re: Perl Humor
by JaWi (Hermit) on Sep 20, 2002 at 10:29 UTC
    This one keeps cracking me up over and over again:

    ``Can I get a YACC grammar for the Perl language?

    Sorry, but as you must surely be aware by now, the only animals supported by Perl are ruminants such as camels and llamas. However, Yacc support may be forthcoming with version 5.007.''

    Hilarious...

    -- JaWi

    "A chicken is an egg's way of producing more eggs."

Re: Perl Humor
by BrowserUk (Patriarch) on Sep 20, 2002 at 10:48 UTC

    That tomorrows date function reminds me of being a newly graduated Mech. Eng. (a long-distant, former me).

    I was so smug because unlike several of my equally new collegues I didn't fall for the usual Mech.Eng. hazings of "Go to the stores and ask them for a long weight!" or "Quick! Get me a left-handed screw-driver!".

    Of course, when I went all through the palava of traipsing to the stores, filling out the appropriate requisitions in triplicate, being sent upstairs to get signatures from my bosses boss, and then upstairs again for the same from his boss.

    Returning to the stores and having to wait while they arranged for a security guard to escort me back from the central stores to my workshop with this "highly specialised and valuable" piece of equipement.

    Getting back to my workshop and being told to remove the 'metric' vernier protractor from its polished wooden box and being asked to explain to the (now assembled) mass of collegues the exact differences between this and the common imperial vernier protractor, I was somewhat red-faced.

    In fact, I still feel myself flush slightly whenever I think about it.


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

      Surely a metric protractor would measure angles in radians. Sounds like someone fobbed you off with an imperial one because they didn't have the right one in stock :)

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        Actually, years later I did encounter what might be term as a non-imperial (though not metric) protractor. It was marked up in grads (400 grads = 360 degrees).

        I've never found a good explaination of when or where grads are useful as opposed to degrees or radians. They do show up on all three of my scientific calculators and even in the calculator on Windows in scientific mode.

        I just found this which appears blames the grad on the (former) British Imperial Army, so maybe they are imperial and degrees should rightly be called metric.


        Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
      GRAD's rather than DEG's? 400 to a circle, if memory serves. At least it wasn't RAD's.
Re: Perl Humor
by Anonymous Monk on Sep 20, 2002 at 13:20 UTC
    How do I find the largest element in an array?
    Write a foreach loop to scan the elements one at a time, and stop when you get to the largest one.

    Or two passengers on a bus:

    Passenger 1: I'm trying to get to 4th and main, could you tell me how to get there?
    Passenger 2: Sure, just get off two stops before I do.

    I think I could make use of this one as well:

    I tried getpeername and it gave me some weird error message.
    If you got `some weird error' the problem is with your frobobnitz.

    Good stuff =D.

      I thought I remembered reading somewhere here that abigail once returned the question of 'how do I get tomorrow's date' with the answer
      sub tomorrow_date { sleep 86_400; return localtime(); }


      or perhaps I am just mistaken...
      work it harder make it better do it faster makes us stronger more than ever hour after our work is never over.
        abigail is on the list of contributors, and Dominus is the author, if I understood it correctly.
      > If you got `some weird error' the problem is with your frobobnitz.

      I don't get it.

      I suppose someone could have a peer named "error" and that would confuse people. I wonder if I name my kid NULL if that would crash databases and he'd never get junk mail?

Re: Perl Humor
by Django (Pilgrim) on Sep 20, 2002 at 12:01 UTC

    That's an interesting option too ;)

    How do I write OO programs in Perl?
    Put -00 on your #! line, like this:

    #!/usr/bin/perl -00 -w

    ~Django
    "Why don't we ever challenge the spherical earth theory?"

Re: Perl Humor
by Django (Pilgrim) on Sep 20, 2002 at 19:20 UTC

    Recently seen in the CB:

    <dswimboy> how do you stop execution of a program?
    <BrowserUk> Petition the Govenor before Midnight!

    ~Django
    "Why don't we ever challenge the spherical earth theory?"

Re: Perl Humor
by Abigail-II (Bishop) on Sep 25, 2002 at 13:54 UTC
    Nice that you enjoyed two of my submissions. Note that the latter was later optimized by Ilya to:
    sub tomorrow_date { sleep 86_400; my $time = localtime; sleep -86_400; return $time; }

    Abigail

Re: Perl Humor
by gmpassos (Priest) on Sep 21, 2002 at 01:23 UTC
    The best is this 3 questinos, making fun with C and ROMAN Numbers:

    ------------------------------------------
    How do I convert a string to a number?

    Use this atoi function:

    sub atoi { my $t; foreach my $d (split(//, shift())) { $t = $t * 10 + $d; } } $number = atoi("123");
    ------------------------------------------
    How do I convert a number to a string?

    Use sprintf:

    $string = sprintf("%f", 123.45);

    ------------------------------------------
    How can I tell if a string is a number?

    The simplest method is:

    if ($string == "$string") { # It is a number }
    Note the use of the == operator to compare the string to its numeric value. However, this approach is dangerous because the $string might contain arbitrary code such as @{[system "rm -rf /"]} which would be executed as a result of the interpolation process. For safety, use this regular expression:
    if ($var =~ /(?=.)M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0 +,3})/) { print "$var contains a number.\b"; }

    Graciliano M. P.
    "The creativity is the expression of the liberty".

    Edit kudra, 2002-09-21 Fixed literal brackets

      the $string might contain arbitrary code such as @{[system "rm -rf /"]} which would be executed as a result of the interpolation process.
      Heh, that's mocking shell, not C, and really caught me off guard for a moment before the d'uh bells went off.

      Makeshifts last the longest.

Re: Perl Humor
by jeorgen (Pilgrim) on Sep 22, 2002 at 17:20 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://199426]
Approved by ignatz
Front-paged by vagnerr
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-03-19 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found