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!abc123!?!; > > s!xyz123!123xyz!; > > > { > > print; > > } > > } > > > Any help much appreciated. > Brian >
See `perldoc File::Basename` for details. #!/usr/bin/perl use strict; use warnings; use File::Basename; my $dir = dirname( $ARGV[0] ); open my $fh, '<', $ARGV[0] or die "cannot open $ARGV[0]: $!"; while( <$fh> ){ s!abc123!$dir!g; }continue{ print; } close $fh or die "cannot close $ARGV[0]: $!"; __END__ -- Just my 0.00000002 million dollars worth, Shawn "Where there's duct tape, there's hope." Cross Time Cafe "Perl is the duct tape of the Internet." Hassan Schroeder, Sun's first webmaster -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/