Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Open Files in Unix

by oko1 (Deacon)
on Oct 08, 2008 at 03:29 UTC ( #715899=note: print w/replies, xml ) Need Help??

in reply to Open Files in Unix

Rather than using an external, non-portable program, you can use File::Find - it comes with Perl, and works pretty well. It also seems like you were trying to imitate the functionality of Tie::File without actually using it - so that didn't work either. Here's an example of how you might use those two to do what you want:

#!/usr/bin/perl -w use strict; use File::Find; use Tie::File; find(\&wanted, '/opt/tivoli/itcam/was/DC/'); sub wanted { return unless /; tie my @file, 'Tie::File', $_ or die "$_: $!\n"; s/DEBUG_MIN/WARN/g for @file; untie @file; }

The second script is close enough to the first one that I'm going to take the easy way out and say "Solution is trivial, and left as an exercise for the student." :)

"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^2: Open Files in Unix
by JavaFan (Canon) on Oct 08, 2008 at 06:44 UTC
    Rather than using an external, non-portable program...

    But 'find' is quite portable. Furthermore, the OP mentioned in his title he was using Unix. 'find' has not only been ported to all Unix flavour, it's also found on (almost) any Unix system.

      Is it? Please try "find -iname '*foo'" or "find -regextype posix-egrep '[abc]\.html'" on, say, a Solaris system - or one with OS/X. A plain "find" (i.e., no options) would serve the OP's purpose - but it is not portable, and its use in scripts should be discouraged.

      "Language shapes the way we think, and determines what we can think about."
      -- B. L. Whorf
        You mean, as opposed to the POSIX egrep semantics of the Perl regexp engine? Oh wait.

        It's kind of silly to come up with exotic options of one implementation a find to claim it's non-portable when 1) the OP doesn't need them and 2) said exotic options aren't available in File::Find without a lot of work either.

        I just tested the script. It runs with no errors but non of the changes are made. what could be wrong?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://715899]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-06-20 20:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.