Go to Google Groups Home  
Web    Images    Groups    News    Froogle    more »
  Advanced Groups Search
  Preferences    
   
 Groups Search result 4 for scrunch 
 Perl Programming • Experts in Perl Staffing & Projects Fortune 500 Clients! • www.levelacuity.comSponsored Links 
 Perl Editor • Award-winning professional IDE ActiveState Komodo - Free Trial • www.ActiveState.com/Komodo
 OptiPerl Visual Editor • Code Perl easier. Amazing features! Download now a 30-day trial. • www.optiperl.com
Search Result 4
From: Randal L. Schwartz @ Stonehenge (merlyn@intelob.intel.com)
Subject: FIXED Perl line-scruncher solution (was Re: Scrunch blank lines)
This is the only article in this thread
View: Original Format
Newsgroups: comp.lang.c
Date: 1989-03-30 13:59:43 PST
In article <4257@omepd.UUCP>, a rather dingy merlyn@intelob writes:
| Here's my solution, just 5 lines of (mostly readable :-) Perl...
| 
| #!/usr/bin/perl
| for ($file = "stdin", $line = 1; $_ = <stdin>;) {
|  ($line = $1, $file = $2, $sync = 0, next) if /^#\W*(\d+)\W+"(.*)"\W*$/;
|  ($sync = 0, $line++, next) if /^\W*$/;
|  printf "#line %d \"%s\"\n", $line, $file unless $sync++;
|  print; $line++;
| }

Arrrgh.  Someone should beat into my head that non-word != whitespace.
All the '\W' up there should be '\s'. Anyway, for those of you that
want the "new and improved" version, try this (I call it "seepp"):

---------------------------------------- cut here --------------------
#!/usr/bin/perl
open(CPP,$a = "/lib/cpp " . join(" ",@ARGV) . "|") ||
 die "Cannot exec '$a' ($!)\n";
for ($file = "/dev/null", $line = 1; $_ = <CPP>;) {
 ($file = $1, $line = $2, $sync = 0, next) if /^#\s*"(.*)"\s+(\d+)\s*$/;
 ($file = $1, $line++, $sync = 0, next) if /^#\s*"(.*)"\s*$/;
 ($line = $1, $file = $2, $sync = 0, next) if /^#\s*(\d+)\s+"(.*)"\s*$/;
 ($line = $1, $sync = 0, next) if /^#\s*(\d+)\s*$/;
 ($sync = 0, $line++, next) if /^\s*$/;
 printf "#line %d \"%s\"\n", $line, $file unless $sync++;
 print; $line++;
}
close(CPP) || die "Cannot close '$a' ??? ($!)\n";
exit(0);
---------------------------------------- cut here --------------------
(side note to Larry: if you wanna stick this in 'eg', go ahead...)

Probably should have had lunch first,
-- 
/     Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095        \
|        on contract to BiiN (for now :-) Hillsboro, Oregon, USA.             |
|<@intel-iwarp.arpa:merlyn@intelob.intel.com> ...!uunet!tektronix!biin!merlyn |
\     Cute quote: "Welcome to Oregon... home of the California Raisins!"      /


Google Home - Advertising Programs - Business Solutions - About Google

©2004 Google