Re: Conditional replace

2008-10-22 Thread brian54321uk
Rob Coops wrote: snip open (IN, +dummy.txt); @file = IN; close IN; for ( my $i = 0; $i scalar @file; $i++ ) { # loop trought the file line by line if ( $file =~ m/$ARGV0/g ) { # look for argument $ARGV0 $file =~ s/$ARGV0(\b.*)/$ARGV1$1/g; # replace argument $ARGV0 with $ARGV1 $file =~

Returning character from string

2008-10-20 Thread brian54321uk
Hi, I'm stuck with what will probably turn out to be a simple solution, I've been scouring google for ages, and can't find anything close to what I'm looking for. Given that $fred = 10 $barney = abcdefghijklmn how do I get $wilma = j Thanks Brian -- To unsubscribe, e-mail: [EMAIL

Re: Returning character from string

2008-10-20 Thread brian54321uk
Rob Dixon wrote: brian54321uk wrote: Hi, I'm stuck with what will probably turn out to be a simple solution, I've been scouring google for ages, and can't find anything close to what I'm looking for. Given that $fred = 10 $barney = abcdefghijklmn how do I get $wilma = j my $wilma

Re: Returning character from string

2008-10-20 Thread brian54321uk
John W. Krahn wrote: brian54321uk wrote: Hi, Hello, I'm stuck with what will probably turn out to be a simple solution, I've been scouring google for ages, and can't find anything close to what I'm looking for. Given that $fred = 10 $barney = abcdefghijklmn how do I get $wilma = j

Re: Returning character from string

2008-10-20 Thread brian54321uk
Rob Dixon wrote: brian54321uk wrote: Hi, I'm stuck with what will probably turn out to be a simple solution, I've been scouring google for ages, and can't find anything close to what I'm looking for. Given that $fred = 10 $barney = abcdefghijklmn how do I get $wilma = j my $wilma

Re: Returning character from string

2008-10-20 Thread brian54321uk
brian54321uk wrote: Rob Dixon wrote: brian54321uk wrote: Hi, I'm stuck with what will probably turn out to be a simple solution, I've been scouring google for ages, and can't find anything close to what I'm looking for. Given that $fred = 10 $barney = abcdefghijklmn how do I get $wilma

Re: Returning character from string

2008-10-20 Thread brian54321uk
brian54321uk wrote: Rob Dixon wrote: brian54321uk wrote: Hi, I'm stuck with what will probably turn out to be a simple solution, I've been scouring google for ages, and can't find anything close to what I'm looking for. Given that $fred = 10 $barney = abcdefghijklmn how do I get $wilma

Re: Returning character from string

2008-10-20 Thread brian54321uk
brian54321uk wrote: brian54321uk wrote: Rob Dixon wrote: brian54321uk wrote: Hi, I'm stuck with what will probably turn out to be a simple solution, I've been scouring google for ages, and can't find anything close to what I'm looking for. Given that $fred = 10 $barney = abcdefghijklmn

Re: Delete file if it contains x y or z

2008-09-06 Thread brian54321uk
John W. Krahn wrote: Aruna Goke wrote: brian54321uk wrote: Aruna Goke wrote: Mr. Shawn H. Corey wrote: On Fri, 2008-09-05 at 19:09 +0100, brian54321uk wrote: HI again I would like to test a folder full of files, and if a file contains abc123blue or xyz357green then that file

Re: Delete file if it contains x y or z

2008-09-06 Thread brian54321uk
John W. Krahn wrote: Dr.Ruud wrote: brian54321uk schreef: I would like to test a folder full of files, and if a file contains abc123blue or xyz357green then that file is to be deleted. What would be the best way of achieving this please? I would use `grep -l` to get the list of filenames

Re: Delete file if it contains x y or z

2008-09-06 Thread brian54321uk
Aruna Goke wrote: brian54321uk wrote: Aruna Goke wrote: Mr. Shawn H. Corey wrote: On Fri, 2008-09-05 at 19:09 +0100, brian54321uk wrote: HI again I would like to test a folder full of files, and if a file contains abc123blue or xyz357green then that file is to be deleted. What would

Re: Delete file if it contains x y or z

2008-09-06 Thread brian54321uk
Peter Scott wrote: On Fri, 05 Sep 2008 19:09:25 +0100, brian54321uk wrote: I would like to test a folder full of files, and if a file contains abc123blue or xyz357green then that file is to be deleted. What would be the best way of achieving this please? One way: use strict; use warnings

Re: Delete file if it contains x y or z

2008-09-06 Thread brian54321uk
[EMAIL PROTECTED] wrote: Here's another way, but not necessarily the best Perl, but it does work: #!/usr/bin/env perl use strict; use warnings; my @filelist=STDIN; chomp @filelist; my $match_strings=qr '(abc123blue|xyz357green)'; my ($file, ); foreach $file (@filelist) { #print file=$file\n;

Delete file if it contains x y or z

2008-09-05 Thread brian54321uk
HI again I would like to test a folder full of files, and if a file contains abc123blue or xyz357green then that file is to be deleted. What would be the best way of achieving this please? If however, it would be simpler for the script to empty the files contents, that's not a problem as I

substitute using directory name

2008-09-03 Thread brian54321uk
Hi I would like to replace a string of characters in a file to the name of the directory it is in. Thefore, in the example below, I would like to know how to replace ? open( F, $ARGV[0] ); while( F ) { s!abc123!?!; s!xyz123!123xyz!; { print; } } Any help much appreciated. Brian

Re: substitute using directory name

2008-09-03 Thread brian54321uk
Mr. Shawn H. Corey wrote: On Wed, 2008-09-03 at 14:55 +0100, brian54321uk wrote: Hi I would like to replace a string of characters in a file to the name of the directory it is in. Thefore, in the example below, I would like to know how to replace ? open( F, $ARGV[0] ); while( F ) { s

Re: substitute using directory name

2008-09-03 Thread brian54321uk
, brian54321uk wrote: Just tested this out and unfortunately instead of dirname replacing abc123, I get a . That's because the dirname is a '.' Try: use Cwd; if( (my $dir = dirname( $file )) eq '.' ){ $dir = cwd(); } -- Just my 0.0002 million dollars worth