Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Sinistral's scratchpad

by Sinistral (Monsignor)
on Aug 15, 2007 at 16:05 UTC ( #632778=scratchpad: print w/replies, xml ) Need Help??

Cool Code Snippets

Count Instances of string in List

my $thing_to_find = 'needle'; my @haystack = ('needle', 'hay', 'more hay', 'yet more hay'); my $needle_count = scalar(grep { /^$thing_to_find$/ } @haystack);

Wait for User Input

sub getAnswer { my $ans; $ans = <STDIN>; chomp($ans); return $ans; }

Pad a String to Provided Length

sub pad { my ($str, $padSize, $padChar, $dir) = @_; my $padding = ""; my $padLength = ""; if ($#_ == 2) { $dir = "right"; } if (length($str) < $padSize) { $padLength = $padSize - length($str); $padding = "$padChar" x $padLength; if ($dir eq "right") { $str = $str . $padding; } else { $str = $padding . $str; } } return $str; }

Excellent Found Nodes

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? | Other CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2023-06-05 00:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (22 votes). Check out past polls.

    Notices?