misconfiguration has asked for the wisdom of the Perl Monks concerning the following question:
OR:if ($remove eq ~ m/^.*\b($remove)\b.*$) { # do stuff here }
Obviously the second logic makes a bit more sense; considering I'm not editing a live file, IF: the second logic should be used, how would I go about generating a random filename?sub clean_the_file { my $sourcefile = "/u/ccsys/CC_print.printers"; # grab the sourcefile and the string to remove as the first and second + arguments my ( $sourcefile, $remove ) = @_; # create a temporary file my $tempfile = # Some random file creation logic; # extract lines from $sourcefile which do NOT have the string to r +emove # note that the \' inserts ticks so that strings with spaces can w +ork, too `grep -v \'$remove\' $sourcefile\n > $tempfile`; # delete source file, then rename working file unlink($sourcefile); rename( $tempfile, $sourcefile ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pattern matching || grep -v which logic is better?
by FunkyMonk (Bishop) on Feb 08, 2008 at 15:24 UTC | |
|
Re: Pattern matching || grep -v which logic is better?
by olus (Curate) on Feb 08, 2008 at 15:21 UTC | |
|
Re: Pattern matching || grep -v which logic is better?
by CountZero (Bishop) on Feb 08, 2008 at 16:21 UTC |