I’ve installed WP-Syntax, a great plugin for WordPress that lets you add code snippets to your blog posts without losing all the formatting.
You can use all manner of languages and even include line numbers if you want. Here’s a snippet from one of my math worksheet makers written in Perl:
5
| use List::Util shuffle; # Use the Shuffle module |
use List::Util shuffle; # Use the Shuffle module
166
167
168
169
170
171
| # define and populate the arrays
my @girlsnames = ('Erin','Anna','Joanne','Sally', 'Mary');
my @boysnames = ('Adam','Ken','Tom','Paul','David', 'Sam');
@girlsnames = shuffle @girlsnames; # shuffle the girls' array
@boysnames = shuffle @boysnames; # shuffle the boys' array |
# define and populate the arrays
my @girlsnames = ('Erin','Anna','Joanne','Sally', 'Mary');
my @boysnames = ('Adam','Ken','Tom','Paul','David', 'Sam');
@girlsnames = shuffle @girlsnames; # shuffle the girls' array
@boysnames = shuffle @boysnames; # shuffle the boys' array
377
378
| $name1 = pop(@boysnames); # assign last name in array to $name1;
$name2 = pop(@girlsnames); # assign last name in array to $name2; |
$name1 = pop(@boysnames); # assign last name in array to $name1;
$name2 = pop(@girlsnames); # assign last name in array to $name2;
If you like, you can find me on Twitter at
@nick_ramsay. I'd love to hear from you!
I actually don’t really understand this post. 🙁 What’s a code snippet? Can you show an actual example of what this code really does?
Stop pulling my leg, Mike. It’s quite obvious what a “code snippet” is, and I’ve commented the actual code so you know what it does. I’m not falling for your trickery! 😉
What is this “code snippet” language thingy that you speak of?
A definition for you:
And another:
Thanks for the definitions. 🙂
Love the photo, Nick. Rikuto looks so cute.I also like the diary updates. I can keep an eye on what you are doing. Ha ha!
You mean the Twitter updates? If you join Twitter.com, you can get those sent directly to your mobile phone! Then you’ll know exactly what I’m doing that very minute! 😉
I’m a little confused…
What you are saying is this plugin displays code snippets as text in a post, right?
(Because normally any code would not show as text)
This would be useful for showing others a bit of code used for x purpose.
Or are you saying something else entirely?
That is exactly what I’m saying, Tori. I’m glad someone understood! 🙂