Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-09-20 01:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls