Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Code Smarter

by japhy (Canon)
on Nov 19, 2000 at 02:18 UTC ( #42374=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    @small = grep { $_->size < 100 } sort $query->all_records;
    # vs.
    @small = sort grep { $_->size < 100 } $query->all_records;
    
  2. or download this
    ($short) = $desc =~ /^(.{0,100})/;
      # breaks on embedded newlines, and is better as
    $short = substr($desc, 0, 100);
    
  3. or download this
    $name = substr($rec,  0, 20);
    $age  = substr($rec, 20,  5);
    $job  = substr($rec, 25, 25);
      # repeated calls to substr() better as unpack()
    ($name,$age,$job) = unpack 'A20 A5 A25', $rec;
    
  4. or download this
    if ($str =~ /jeff/) { ... }
      # why not
    if (index($str,'jeff') > -1) { ... }
      # or if you know that if it's there, it's toward the end:
    if (rindex($str,'jeff') > -1) { ... }
    
  5. or download this
    # (on average)
    s/[abc]*//g;  # is FAR slower than
    s/[abc]//g;   # is slower than
    s/[abc]+//g;  # which is slower than
    tr/abc//d;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://42374]
Approved by root
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2017-06-25 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (567 votes). Check out past polls.