in reply to RE: Re: Help for awk/regex/newbie
in thread Help for awk/regex/newbie
Update: Fixed the loop to only print if the match succeeds, per merlyn#!/usr/bin/perl -w use strict; my @cleanarray = <>; foreach (@cleanarray) { print "$1\n" if m/(\S+)/; }
Now that I think about it though, a mock awk really ought to look like this:
That matches awk's behavior on blank lines better than my first stab.#!/usr/bin/perl -w use strict; my @cleanarray = <>; foreach (@cleanarray) { # The regex always matches so there's no need # for a conditional. m/(\S*)/; print "$1\n"; }
-Matt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: RE: Re: Help for awk/regex/newbie
by merlyn (Sage) on Aug 14, 2000 at 17:38 UTC |