spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / programming/perl / minimal_perl2

[previous] [next]

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Perl as a (Better) Find Command: Part 2

By: Tim Maher

6.4 Processing Filename Arguments

Have you ever run the grep command, only to find yourself suddenly staring at a screen full of blinking graphics characters? Most Unix users should witness this phenomenon sooner or later, because it's not only the closest approximation to the Aurora Borealis you'll ever see on a computer terminal, it's also a rite of passage for Unix newbies.

If you don't know what I'm talking about, feast your eyes on figure 6.1, which shows what happened when a hapless user attempted to search all files under $HOME for lines containing the letter e, using POSIX grep.

Unfortunately for that user, grep doesn't treat $HOME as some kind of magical reference to all the files within the director y it names, as many are prone to assume. Instead, it's taken as the name of the specific file that's to be opened and examined for matches! As luck would have it, this directory file did contain some occurrences of the letter e, so grep dutifully sent the associated "lines" to the screen.

But the terminal interpreted something in that data stream as a request to switch character sets, which is why it's difficult to decipher the output of the who and ls-l commands that came next.

By the way, if you're thinking, "I'm too smart too fall into that trap," consider the related commands shown here, which are just as dangerous in cases where "*" finds a subdirectory it can match:

It's scary to contemplate, but I know from my decades in Unix IT circles that many users issue commands like these all the time; they're just lucky to rarely find matches in the binary files they're inadvertently searching.

Okay, now you understand the problem, and you've seen that it's an easy trap to fall into. So you're probably asking yourself, "Is there any hope of defending the hordes of accident-prone Unix users from these grepological calamities? And what does this have to do with Perl?"

Of course there's hope; and, as usual, our salvation is achieved by Perl coming to the rescue.

Figure 6.1

home / programming / programming/perl / minimal_perl2

[next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

URL: