MESSAGE
DATE | 2011-12-14 |
FROM | Ruben Safir
|
SUBJECT | Re: [NYLXS - HANGOUT] A simple perl script
|
From owner-hangout-outgoing-at-mrbrklyn.com Wed Dec 14 22:48:28 2011 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by www2.mrbrklyn.com (Postfix) id E6712FF99F; Wed, 14 Dec 2011 22:48:27 -0500 (EST) Delivered-To: hangout-outgoing-at-www2.mrbrklyn.com Received: by www2.mrbrklyn.com (Postfix, from userid 28) id D5435FFEAA; Wed, 14 Dec 2011 22:48:27 -0500 (EST) Delivered-To: hangout-at-mrbrklyn.com Received: from mail-qy0-f172.google.com (mail-qy0-f172.google.com [209.85.216.172]) by www2.mrbrklyn.com (Postfix) with ESMTP id 7C58AFFAD8 for ; Wed, 14 Dec 2011 22:48:27 -0500 (EST) Received: by qcsf15 with SMTP id f15so1160455qcs.17 for ; Wed, 14 Dec 2011 19:50:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=zCPcGCPN2HHkkCeN9j1H7WNbSukPpKRnYVppUSEIsc8=; b=D1bM3aDT1ayjg8wptZ4x3o3FoBOTcWVUgH8oCiDZrmHrgINRSzRlpBbINXSQ2ACANv Q7nb6+WfJRzuXcjWL2RSHYP5Dq2vEZoAbwRSva3gfE4VreZWEwU5hs1TK0H3gcpIwpyd b7poDAOScwY7A9LFDwG76wvO3eqoZCBdHSDEo= Received: by 10.224.32.20 with SMTP id a20mr2523530qad.61.1323921007405; Wed, 14 Dec 2011 19:50:07 -0800 (PST) Received: from [10.0.0.24] (www2.mrbrklyn.com. [96.57.23.82]) by mx.google.com with ESMTPS id dk9sm10158230qab.0.2011.12.14.19.50.06 (version=SSLv3 cipher=OTHER); Wed, 14 Dec 2011 19:50:07 -0800 (PST) Message-ID: <4EE96E6D.1050205-at-gmail.com> Date: Wed, 14 Dec 2011 22:50:05 -0500 From: Ruben Safir User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111101 SUSE/3.1.16 Thunderbird/3.1.16 MIME-Version: 1.0 To: hangout-at-mrbrklyn.com CC: Elfen Magix Subject: Re: [NYLXS - HANGOUT] A simple perl script References: <20111214070833.GA11058-at-panix.com> <1323908859.93530.YahooMailNeo-at-web38006.mail.mud.yahoo.com> <4EE96DA4.2050105-at-gmail.com> In-Reply-To: <4EE96DA4.2050105-at-gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-hangout-at-mrbrklyn.com Precedence: bulk Reply-To: hangout-at-mrbrklyn.com
On 12/14/2011 10:46 PM, Ruben Safir wrote: > On 12/14/2011 07:27 PM, Elfen Magix wrote: >> I need a simple thing that goes through a file to find "Chapter [and >> a number]". Then it must increment that number by 1 and resave the >> file without altering nothing else. >> >> I know I've seen this, and even wrote one years ago myself, but I >> cant for the life of me remember how! >> >> Thanks. >> > How can I copy a file? > (contributed by brian d foy) > > Use the "File::Copy" module. It comes with Perl and can do a > true copy > across file systems, and it does its magic in a portable fashion. > > use File::Copy; > > copy( $original, $new_copy ) or die "Copy failed: $!"; > > If you can't use "File::Copy", you'll have to do the work > yourself: > open the original file, open the destination file, then print > to the > destination file as you read the original. You also have to > remember to > copy the permissions, owner, and group to the new file. > > > perlfaq5 > > > How do I traverse a directory tree? > (contributed by brian d foy) > > The "File::Find" module, which comes with Perl, does all of the > hard > work to traverse a directory structure. It comes with Perl. You > simply > call the "find" subroutine with a callback subroutine and the > directories you want to traverse: > > use File::Find; > > find( \&wanted, -at-directories ); > > sub wanted { > # full path in $File::Find::name > # just filename in $_ > ... do whatever you want to do ... > } > > The "File::Find::Closures", which you can download from CPAN, > provides > many ready-to-use subroutines that you can use with "File::Find". > > The "File::Finder", which you can download from CPAN, can help you > create the callback subroutine using something closer to the > syntax of > the "find" command-line utility: > > use File::Find; > use File::Finder; > > my $deep_dirs = > File::Finder->depth->type('d')->ls->exec('rmdir','{}'); > > find( $deep_dirs->as_options, -at-places ); > > The "File::Find::Rule" module, which you can download from > CPAN, has a > similar interface, but does the traversal for you too: > > use File::Find::Rule; > > my -at-files = File::Find::Rule->file() > > ->name( '*.pm' ) > ->in( > -at-INC ); > >
Also see
perldoc -f opendir
opendir DIRHANDLE,EXPR Opens a directory named EXPR for processing by "readdir", "telldir", "seekdir", "rewinddir", and "closedir". Returns true if successful. DIRHANDLE may be an expression whose value can be used as an indirect dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined scalar variable (or array or hash element), the variable is assigned a reference to a new anonymous dirhandle. DIRHANDLEs have their own namespace separate from FILEHANDLEs.
See example at "readdir".
|
|