Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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 /cynlogging.properties/; 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


Comment on Re: Open Files in Unix
Download Code
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
        I just tested the script. It runs with no errors but non of the changes are made. what could be wrong?
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://715899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-11-22 21:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (125 votes), past polls