You are localizing $^I too late - after you call your subroutine. Move it to the line before. Or better yet, put it inside the subroutine itself, since that's what you really meant.
--edan -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Levenglick Dov-RM07994 Sent: Tuesday, September 18, 2007 08:54 To: Perl in Israel Subject: [Israel.pm] $^I question Perldoc says: % perl -i.orig -pe 's/foo/bar/g' *.c you can use the following equivalent code in your program: local $^I = '.orig'; local @ARGV = glob("*.c"); while (<>) { s/foo/bar/g; print; } I have a script which follows this, however it is not doing in place editing, rather it is printing to the STDOUT (notice, I am running on Win32). Any ideas? use strict; use warnings; use Cwd; &print_usage unless defined $ARGV[0] and -d $ARGV[0]; my $search_pattern = "blah blah blah"; iterate_over_dir($ARGV[0]); local $^I = '.xxbakxx'; sub iterate_over_dir { my $curdir = Cwd::realpath($_[0]); chdir $curdir; opendir DIR, "." or warn "Can't open directory $curdir ($!)\n" and return; my @dirs = grep { -d && !/^\.{1,2}$/} readdir DIR; rewinddir DIR; local @ARGV = grep {-f && /\.(?:c|h|asm)$/} readdir DIR; closedir DIR; # recursivly call funciton for directories foreach (@dirs) { iterate_over_dir($_); chdir $curdir; } #change files return unless scalar @ARGV; while (<>) { print unless /$search_pattern/; } } sub print_usage { print STDERR "USAGE: $0 <dir_name>\n"; exit -1; } Best Regards, Dov Levenglick SmartDSP OS Development Team, DevTech, Technology and System Organization Freescale Semiconductor Israel Tel. +972-9-952-2804 The information contained in this email is classified as: [ ] Freescale General Business Information [ ] Freescale Internal Use Only [ ] Freescale Confidential Proprietary [x] Personal Memorandum _______________________________________________ Perl mailing list [email protected] http://perl.org.il/mailman/listinfo/perl _______________________________________________ Perl mailing list [email protected] http://perl.org.il/mailman/listinfo/perl
