Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A really short little ditty to take a file delimited by '%' characters (on lines by themselves) then randomly select an entry, then print it to the .signature file.

Literally taken straight from my ~/scripts directory, all still hardcoded. Pick it to pieces, but remember it's just a hack :)

First few lines of my .signature.rot file. Note the first line is blank, and there needn't be a trailing newline at the end:

Leo: (July 23 - Aug. 22) When driving through the desert, you should never stop and eat mysterious piles of birdseed, even if "FREE BIRDSEED" signs are stuck in them. % "Reality is that which, when you stop believing in it, doesn't go away". -- Philip K. Dick % So, Lone Starr, now you see that evil will always triumph, because good is dumb. -- Dark Helmet % Thank you for pressing the self-destruct button. This ship will self-destruct in three minutes. % Do you make up these questions, Mr. Holden, or do they write them down for you? % Yes, questions. Morphology, longevity, incept dates. % "Begun, this clone war has." Donate to the House With No Sentence Structure. Dedicated to assisting grammatically disadvantaged Jedi for over 900 years.
#!/usr/bin/perl use IO::File; $/ = "%"; open(FILE, "/home/hagus/.signature.rot"); while (<FILE>) { $tmp = $_; $tmp =~ s/%//g; push @a, $tmp; } close(FILE); my $fh = new IO::File("/dev/urandom", "r"); my $foo = $fh->read($value, 100); $fh->close(); my $num = unpack("S*", $value); my $index = $num % (@a + 0); open(FILE, ">/home/hagus/.signature"); print FILE $a[$index] . "\n"; close(FILE);

In reply to Signature rotation. by hagus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-26 06:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found