Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Code Smarter

by japhy (Canon)
on Nov 19, 2000 at 02:18 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-20 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found