[22810] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5031 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 23 21:05:43 2003

Date: Fri, 23 May 2003 18:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 23 May 2003     Volume: 10 Number: 5031

Today's topics:
    Re: 32 bits checksum calculation <dmn@box43.pl>
    Re: Copying all files in a directory <stevea@wrq.com>
        counter <no.spam@this.addy.ta>
    Re: counter <bwalton@rochester.rr.com>
    Re: counter <abigail@abigail.nl>
    Re: counter <no.spam@this.addy.ta>
    Re: counter <bwalton@rochester.rr.com>
    Re: counter <no.spam@this.addy.ta>
    Re: counter <cat@no-spam.com>
    Re: Delete Element From Array? <jkeen@concentric.net>
    Re: extract pattern (vaidehi)
    Re: extract pattern <jkeen@concentric.net>
    Re: extract pattern (Tad McClellan)
        Forum <Anonymous-Remailer@nowhere.com>
        Help: Delete Element From Array? (entropy123)
    Re: Help: Delete Element From Array? <abigail@abigail.nl>
        Help: Install VCG on Linux and Use GRAPH Module... (entropy123)
    Re: is flock() needed when reading a DB ? <garry@ifr.zvolve.net>
        multiline string handling <Rene.Scheibe@gmx.net>
    Re: multiline string handling <jkeen@concentric.net>
    Re: multiline string handling (Tad McClellan)
    Re: Parsing and replacing html then putting it all back <nospam@raytheon.com>
        Pattern Match - substitute a string after the match (Marcello)
    Re: Pattern Match - substitute a string after the match <tzz@lifelogs.com>
    Re: removing last part of a line <bigj@kamelfreund.de>
    Re: removing last part of a line (ram)
    Re: removing last part of a line <REMOVEsdnCAPS@comcast.net>
    Re: removing last part of a line <krahnj@acm.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 23 May 2003 23:15:11 +0200
From: "Darek N" <dmn@box43.pl>
Subject: Re: 32 bits checksum calculation
Message-Id: <bam2rc$hf2$1@atlantis.news.tpi.pl>


>Well if you've already decided that you are going to slurp the file
>then your question not how to calculate the checksum of a file but
>rather the checksum of a string.

What is the difference ? I thought that calculating checksum of some
file you do it on the data that that file contains ?


>--
>     \\   ( )
>  .  _\\__[oo
> .__/  \\ /\@
> .  l___\\
>  # ll  l\\
> ###LL  LL\\




------------------------------

Date: Fri, 23 May 2003 21:51:59 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Copying all files in a directory
Message-Id: <uznld49hc.fsf@wrq.com>

naina_r@yahoo.com (Naina) writes:

>Hi 
>I used File::Copy and what I was able to do was copy some specific files.
>Can i copy all files in a directory to another directory?I tried *.*,it doesnt
>work.For example i need to copy all files in newdir to temp...
>Eg 
>copy ("C:/temp/newdir/*.*", "k:/temp/*.*");
>
>
>Any suggestion would be welcome.
>Thanks
>Naina

I used the symirror example (9.11) from 'the Cookbook' (Christiansen &
Torkington) and wrote this routine to copy the contents of a one
directory to another, preserving subdirectories.  No warranties :)

-- 
-- Steve
==========================================================================
sub copy_tree {
   # These are actually at the top of the script this sub is
   # in, but I'm putting them here just for this post. Hopefully
   # I didn't omit one.
   use File::Find;
   use File::Copy;
   use File::Path;

   my ($srcdir, $dstdir) = @_;
   die "source directory $srcdir is not valid" unless -d $srcdir;

   # create dstdir if it doesn't exist.  If it does, make sure it's
   # a directory and not a file.
   my $dstdir_exists = -d $dstdir;
   unless ($dstdir_exists) {
      die "$dstdir exists but is not a directory" if defined $dstdir_exists;
      mkpath "$dstdir" or die "Failed to create $dstdir: $!";
   }

   my $curdir = cwd();
   chdir $srcdir or die "Can't cd to $srcdir: $!";
   find( sub {
      my ($dev, $ino, $mode) = lstat($_);
      my $name = $File::Find::name;
      unless($name eq '.' or $name eq '..') {
         $mode &= 0777;
         $name =~ s!^\./!!;
         if ( -d $_ ) {
            mkdir("$dstdir/$name", $mode) or die "Can't make dir $dstdir/$name: $!";
         }
         else {
            copy "$srcdir/$name" => "$dstdir/$name"
               or die "Can't copy $srcdir/$name to $dstdir/$name: $!";
         }
      }
   }, '.');
   # this is needed in the larger context of the original script,
   # but probably not if this were stand-alone.
   chdir $curdir or warn "Failed to cd back to $curdir: $!";
}


------------------------------

Date: Sat, 24 May 2003 01:28:19 +0100
From: "Brian H供" <no.spam@this.addy.ta>
Subject: counter
Message-Id: <C0zza.11486$Mu3.224864@newsfep4-glfd.server.ntli.net>

Hi.
Would someone be kind enough to amend the following *.pl so that I can count
alphanumerics please.
Sorry to ask, but I'm going round in circles here.

TIA
Brian

use strict;

my ( $line, %hash, @array, $key, $value, $i );

open( F, $ARGV[0] );

while( chomp( $line = <F> ) ) {

 $hash{ int( $line ) } += 1;

}

foreach $key ( sort { $a <=> $b } ( keys( %hash ) ) ) {

 printf( "%2d\t%3d\n", $key, $hash{ $key } );

}




------------------------------

Date: Sat, 24 May 2003 00:48:25 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: counter
Message-Id: <3ECEBF4A.40701@rochester.rr.com>

Brian H供 wrote:

> Hi.
> Would someone be kind enough to amend the following *.pl so that I can count
> alphanumerics please.


It is not clear at all exactly what you are trying to do.  Based on your 
code, I will assume you want to count the number of alphanumeric 
characters in each line, and increment a hash keyed by that number of 
characters for each line read.


 ...
> Brian
> 
> use strict;
> 
> my ( $line, %hash, @array, $key, $value, $i );
> 
> open( F, $ARGV[0] );
> 
> while( chomp( $line = <F> ) ) {
> 
>  $hash{ int( $line ) } += 1;


The int function will force a numeric conversion on the string in $line, 
and than truncate it to the nearest integer towards zero.  If the string 
doesn't start out with something numberlike, the result will be zero. 
Doesn't sound like "counting alphanumerics" to me.


> 
> }
> 
> foreach $key ( sort { $a <=> $b } ( keys( %hash ) ) ) {
> 
>  printf( "%2d\t%3d\n", $key, $hash{ $key } );
> 
> }


Try:

    use strict;
    use warnings;
    my %hash;
    $hash{y/a-zA-Z_//}++ while(<>);
    for(sort {$a<=>$b} keys %hash){
       printf "%2d\t%3d\n",$_,$hash{$_};
    }

-- 
Bob Walton



------------------------------

Date: 24 May 2003 00:52:24 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: counter
Message-Id: <slrnbctgi7.kuj.abigail@alexandra.abigail.nl>

Brian H供 (no.spam@this.addy.ta) wrote on MMMDLIII September MCMXCIII in
<URL:news:C0zza.11486$Mu3.224864@newsfep4-glfd.server.ntli.net>:
``  Hi.
``  Would someone be kind enough to amend the following *.pl so that I can count
``  alphanumerics please.

What do you mean by that?


``  while( chomp( $line = <F> ) ) {


You didn't happen to learn perl at HP Education, did you?



Abigail
-- 
perl -we '$| = 1; $_ = "Just another Perl Hacker\n";  print
          substr  $_ => 0, 1 => "" while $_ && sleep 1 => 1'


------------------------------

Date: Sat, 24 May 2003 01:56:48 +0100
From: "Brian H供" <no.spam@this.addy.ta>
Subject: Re: counter
Message-Id: <irzza.11496$Mu3.224886@newsfep4-glfd.server.ntli.net>

X-No-Archive: Yes
My monitor and keyboard are coffee coloured.
I had a mouthful of coffee when I noticed Abigail said:

> Brian H供 (no.spam@this.addy.ta) wrote on MMMDLIII September MCMXCIII in
> <URL:news:C0zza.11486$Mu3.224864@newsfep4-glfd.server.ntli.net>:
> ``  Hi.
> ``  Would someone be kind enough to amend the following *.pl so that I can
> count ``  alphanumerics please.
>
> What do you mean by that?
>
>
> ``  while( chomp( $line = <F> ) ) {
>
>
> You didn't happen to learn perl at HP Education, did you?
>
>

No I'm learning PERL from a book all on my own.




------------------------------

Date: Sat, 24 May 2003 00:57:08 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: counter
Message-Id: <3ECEC155.6060202@rochester.rr.com>

Bob Walton wrote:

> Brian H供 wrote:
 ...
>    $hash{y/a-zA-Z_//}++ while(<>);


Oops, make that:


      $hash{y/a-zA-Z_0-9//}++ while(<>);


to include the numeric characters.

-- 
Bob Walton



------------------------------

Date: Sat, 24 May 2003 02:02:22 +0100
From: "Brian H供" <no.spam@this.addy.ta>
Subject: Re: counter
Message-Id: <wwzza.11499$Mu3.223180@newsfep4-glfd.server.ntli.net>

X-No-Archive: Yes
My monitor and keyboard are coffee coloured.
I had a mouthful of coffee when I noticed Bob Walton said:

> Brian H供 wrote:
>
>> Hi.
>> Would someone be kind enough to amend the following *.pl so that I can count
>> alphanumerics please.
>
>
> It is not clear at all exactly what you are trying to do.  Based on your
> code, I will assume you want to count the number of alphanumeric
> characters in each line, and increment a hash keyed by that number of
> characters for each line read.
>

What I would like to do is count the number of instances of repeated words, 1
word per line.
The example I gave is of a counter that ignores alpha in it's count.
If I have six lines that consist of, say, fred001, I want it to tally the
instamces of fred001 and not (as with my example) just 001.





------------------------------

Date: Sat, 24 May 2003 11:15:04 +1000
From: Cat <cat@no-spam.com>
Subject: Re: counter
Message-Id: <3ECEC798.55EE37FC@no-spam.com>

"Brian H供" wrote:
> 
> Hi.
> Would someone be kind enough to amend the following *.pl so that I can count
> alphanumerics please.
> Sorry to ask, but I'm going round in circles here.
> 
> TIA
> Brian
> 
> use strict;
> 
> my ( $line, %hash, @array, $key, $value, $i );
> 
> open( F, $ARGV[0] );
> 
> while( chomp( $line = <F> ) ) {
> 
>  $hash{ int( $line ) } += 1;
> 
> }
> 
> foreach $key ( sort { $a <=> $b } ( keys( %hash ) ) ) {
> 
>  printf( "%2d\t%3d\n", $key, $hash{ $key } );
> 
> }

Dood, can you post a few lines of the $ARGV[0] file and a brief explanation
of what you are trying to achieve with that input.


------------------------------

Date: 23 May 2003 22:42:46 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Delete Element From Array?
Message-Id: <bam856$fc3@dispatch.concentric.net>


"entropy123" <email_entropy123@yahoo.com> wrote in message
news:90cdce37.0305231437.28c8e861@posting.google.com...
> Hey all,
>
> How do I quickly and easily delete an element from an array?
>
> say
>
> @a = (C1 C2 C3 C4 C5);
>
> and I want to delete C3. I can't figure out how to pull this off...
>
Consult the docs:
perldoc -f splice




------------------------------

Date: 23 May 2003 11:49:44 -0700
From: vaidehi_30@yahoo.com (vaidehi)
Subject: Re: extract pattern
Message-Id: <b20ff12f.0305231049.9b2b3fc@posting.google.com>

Eric Wilhelm <ericw@nospam.ku.edu> wrote in message news:<pan.2003.05.22.23.27.33.868185.10673@nospam.ku.edu>...
> On Thu, 22 May 2003 21:09:47 -0500, Sara wrote:
> 
> > vaidehi_30@yahoo.com (vaidehi) wrote in message
> > news:<b20ff12f.0305221456.7e72faa2@posting.google.com>...
> >> I have got strings like this one:
> >> 1: 196.37.75.158:1024 - 10.10.1.12:79 (a2b)             6>    6<
> >> (complete)
>  
> > * or lots of others?
> 
> if it always has spaces in the same places:
> 
> $result = join(" ",(split(/\s+/, $string)[1..3]);
> use list context and range addressing
> (and make it a little more clear what you mean than a hairy regex)
> 
> to break the data down into finer bits, just use /:|\s+/ or whatever and
> maybe save to an array
> 
> --Eric


Hello all,

Thanks for your excellent feedbacks!!!

-Vaidehi


------------------------------

Date: 23 May 2003 22:44:36 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: extract pattern
Message-Id: <bam88k$fc3@dispatch.concentric.net>


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbcqqlb.3id.tadmc@magna.augustmail.com...
> James E Keenan <jkeen@concentric.net> wrote:
>
> > $str =~ /^.*: (.*?)\(/;
> > my $sought = $1 if defined $1;
>
>
> You should never use the dollar-digit variables unless you have
> first ensured that the match succeeded.
>
> $1 can be defined even when the match above fails.
>
Under what circumstances ... other than from a previous successful match?

>
>    if ( $str =~ /^.*: (.*?)\(/ ) { # safe to use $1

Okay.




------------------------------

Date: Fri, 23 May 2003 19:06:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: extract pattern
Message-Id: <slrnbctdsj.1l1.tadmc@magna.augustmail.com>

James E Keenan <jkeen@concentric.net> wrote:
> 
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnbcqqlb.3id.tadmc@magna.augustmail.com...
>> James E Keenan <jkeen@concentric.net> wrote:
>>
>> > $str =~ /^.*: (.*?)\(/;
>> > my $sought = $1 if defined $1;
>>
>>
>> You should never use the dollar-digit variables unless you have
>> first ensured that the match succeeded.
>>
>> $1 can be defined even when the match above fails.
>>
> Under what circumstances ... other than from a previous successful match?


Exactly that.

The value may have been set "many" lines of code away.

It is the classic action-at-a-distance problem, the same problem that
makes global variables "bad".


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sat, 24 May 2003 01:14:22 +0100
From: "just sum1" <Anonymous-Remailer@nowhere.com>
Subject: Forum
Message-Id: <zOyza.1835$xh1.1121@news-binary.blueyonder.co.uk>


Can anyone link me up with a cgi forum script... I very new to this so an
easyish one would be nice
I just done a Form mail cgi and enjoyed it so much
Thanx for any help
--


-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com





------------------------------

Date: 23 May 2003 15:37:00 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Help: Delete Element From Array?
Message-Id: <90cdce37.0305231437.28c8e861@posting.google.com>

Hey all,

How do I quickly and easily delete an element from an array?

say

@a = (C1 C2 C3 C4 C5);

and I want to delete C3. I can't figure out how to pull this off...

Thanks,
entropy


------------------------------

Date: 23 May 2003 22:53:54 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Help: Delete Element From Array?
Message-Id: <slrnbct9k2.kuj.abigail@alexandra.abigail.nl>

entropy123 (email_entropy123@yahoo.com) wrote on MMMDLII September
MCMXCIII in <URL:news:90cdce37.0305231437.28c8e861@posting.google.com>:
""  Hey all,
""  
""  How do I quickly and easily delete an element from an array?
""  
""  say
""  
""  @a = (C1 C2 C3 C4 C5);
""  
""  and I want to delete C3. I can't figure out how to pull this off...


Do you mean you want to delete the third element? In that case,
see 'perldoc -f splice'. Or do you want to delete elements that
are equal to 'C3'? In that case, see 'perldoc -f grep'.



Abigail
-- 
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
 |perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
 |perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
 |perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;


------------------------------

Date: 23 May 2003 16:46:40 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Help: Install VCG on Linux and Use GRAPH Module...
Message-Id: <90cdce37.0305231546.6229b89d@posting.google.com>

Hey all,

I'm trying to get up and running on the graph module and so far so
good. Apparently I need to install something called VCG to visualize
the module's output. I've tried to install it in my Linux box but I
can't get the demo to run. The standard instructions don't help much,
is there a website or source of information which might walk a newbie
through the process?

Thanks,
entropy


------------------------------

Date: Fri, 23 May 2003 19:12:43 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: is flock() needed when reading a DB ?
Message-Id: <slrnbcsslb.q9e.garry@zfw.zvolve.net>

On 22 May 2003 19:58:51 -0700, dan baker <botfood@yahoo.com> wrote:
> Garry Williams <garry@ifr.zvolve.net> wrote in message news:
>>     # writers use this:
>> ...
>>     # readers use this:
>> ...
> ----------
> thanks for your very nice simple examples. I am wondering two more
> things
> 
> - if a process that has a lock on a file dies unexpectedly, I am
> assuming that the lock is released.... correct?

Correct.  

> - I test the application on windows 98, and flock() kills the script
> since it is not implemented. I remember seeing somewhere that if the
> flock is enclosed in an eval() it wont kill the script. (wont flock
> the file either, but thats ok in my local testing.) correct?

eval (BLOCK) is used to catch an exception.  See perldoc -f eval.  I
believe that Windows 98 imposes a lock on a file unconditionally.  You
might want to consider examining $^O to see if flock() should be
called at all.  See perldoc perlvar.  

-- 
Garry Williams


------------------------------

Date: Fri, 23 May 2003 23:40:10 +0200
From: "Rene Scheibe" <Rene.Scheibe@gmx.net>
Subject: multiline string handling
Message-Id: <bam4fq$1cm0g$1@ID-65612.news.dfncis.de>

i have a log from a script like this:

val1   val2     (  x,  y)      (  w,  h)
-----------------------------------
1       0.435  (  33,  35)  (  24,  23)
2       0.345  (144,444)  (243,955)
2       0.999  (  22,  44)  (234,  25)
 ...

 ...and i want to put the coordinates
of the rects in a twodimensional array.
when i pipe it into a file i can iterate
through it line per line and extract
the needed contents by this:

open FILE, 'filename';
while (<FILE>)
{
(undef, undef, @rect) = split /[\s,()]+/, $_;
}

but when not using a file and getting the logs
directly by variable as multiline string how to do it?
i read things about $*=1 or /m on regexp but
without some success.

rene




------------------------------

Date: 23 May 2003 22:52:11 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: multiline string handling
Message-Id: <bam8mr$fc8@dispatch.concentric.net>


"Rene Scheibe" <Rene.Scheibe@gmx.net> wrote in message
news:bam4fq$1cm0g$1@ID-65612.news.dfncis.de...
> i have a log from a script like this:
>
> val1   val2     (  x,  y)      (  w,  h)
> -----------------------------------
> 1       0.435  (  33,  35)  (  24,  23)
> 2       0.345  (144,444)  (243,955)
> 2       0.999  (  22,  44)  (234,  25)
> ...
>
> ...and i want to put the coordinates
> of the rects in a twodimensional array.
> when i pipe it into a file i can iterate
> through it line per line and extract
> the needed contents by this:
>
> open FILE, 'filename';
> while (<FILE>)
> {
> (undef, undef, @rect) = split /[\s,()]+/, $_;
> }
>
> but when not using a file and getting the logs
> directly by variable as multiline string how to do it?

Could you explain what you mean by "getting the logs directly by variable as
[a] multiline string"?  To the extent that I understand this, I don't know
why this would be better than iterating thru input 1 line at a time?




------------------------------

Date: Fri, 23 May 2003 19:19:14 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: multiline string handling
Message-Id: <slrnbctek2.1l1.tadmc@magna.augustmail.com>

Rene Scheibe <Rene.Scheibe@gmx.net> wrote:

> ...and i want to put the coordinates
> of the rects in a twodimensional array.
> when i pipe it into a file i can iterate
> through it line per line 

> 
> open FILE, 'filename';
> while (<FILE>)
> {
> (undef, undef, @rect) = split /[\s,()]+/, $_;
> }
> 
> but when not using a file and getting the logs
> directly by variable as multiline string how to do it?


Make a loop that will extract the "lines"  (untested):

   foreach my $line ( /(.*\n)/g ) {
      (undef, undef, @rect) = split /[\s,()]+/, $line;
   }

> i read things about $*=1 


Did you read that its use is deprecated?


> or /m on regexp but
> without some success.


Don't need m//m nor m//s for the above.

m//m makes ^ and $ match based on lines rather than strings,
but you do not need to use any anchors, so m//m is a no-op.

m//s makes . match a newline. We _don't want_ it to match newline,
so m//s would be a bug.  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 23 May 2003 14:57:38 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Parsing and replacing html then putting it all back together again?
Message-Id: <N2vza.3386$c6.3234@bos-service2.ext.raytheon.com>

Shaun wrote:
> Ok so here's the issue:
> 
> I have a script that transforms xml data with it's xsl counter part,
> to create my html ($html).
> 
> I need to parse $html for the first block, middle block and last block
> of data.  The begining of the middle block of data is seperated by
> <!--\(--> (simply trying to find a unique set of characters for perl
> to find) and ends with <!--\)--> ofcourse marking the begining of the
> last block.
> 
> So I need to be able to take the middle block of data, and replace it
> with a new block of data, then combine the first, new middle, and last
> block of data to produce a new $html =)
> 
> Any modules out there with this type of functionality built in?  Be
> gentle, I'm a novice.

Randall Schwartz deals almost exactly with this kind of issue (if not 
exactly) in the June 2003 edition (I believe) of _Linux Magazine_ in his 
"Perls of Wisdom" column.  I don't have the article here, but he used 
HTML::Parser and some XML components to accomplish this.  Was quite nice 
and straight forward.  It may be worth having a look at the newstands 
for it.  I see the issue isn't on their web site yet.

Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN

email: olivec(AT)indy(DOT)raytheon(DOT)com



------------------------------

Date: 23 May 2003 16:25:49 -0700
From: amlino2k@yahoo.com (Marcello)
Subject: Pattern Match - substitute a string after the match
Message-Id: <d0b334f6.0305231525.3e1c13e9@posting.google.com>

Hi,

I am trying to automate a table creation process... As an example, I
have a huge file called tables.txt. I want to match the table
"ACCOUNTS" and then substitute the INITIAL 131072 and NEXT 131072 to
INITIAL 1M and NEXT 1M. This has to happen just in the "ACCOUNTS"
block.
Each block in the file starts with CREATE and ends with a slash /.

Does anyone have an example of how can I accomplish this? Any help is
appreciated.

tables.txt sample ->

CREATE TABLE "ACCOUNTING_ROLE"
(       "ROLE_CODE" VARCHAR2(15),
"ROLE_DESC" VARCHAR2(30),
"ROLE_TYPE" VARCHAR2(2)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "TEST"
/
CREATE TABLE "ACCOUNTS"
(       "ACCOUNT_ID" VARCHAR2(8),
"MAINT_FLAG" VARCHAR2(1),
"STATUS" VARCHAR2(1),
 ...
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "TEST"
/
 ...
 ....
 .....


Thanks.


------------------------------

Date: Fri, 23 May 2003 20:52:12 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Pattern Match - substitute a string after the match
Message-Id: <4nu1blgo8z.fsf@lockgroove.bwh.harvard.edu>

On 23 May 2003, amlino2k@yahoo.com wrote:
> I am trying to automate a table creation process... As an example, I
> have a huge file called tables.txt. I want to match the table
> "ACCOUNTS" and then substitute the INITIAL 131072 and NEXT 131072 to
> INITIAL 1M and NEXT 1M. This has to happen just in the "ACCOUNTS"
> block.
> Each block in the file starts with CREATE and ends with a slash /.
> 
> Does anyone have an example of how can I accomplish this? Any help
> is appreciated.

Look at the CPAN Parse::RecDescent module.  What you describe is
possible with regular expressions, but Parse::RecDescent will probably
serve you better in the long run.

Ted


------------------------------

Date: Fri, 23 May 2003 19:37:47 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: removing last part of a line
Message-Id: <pan.2003.05.23.17.37.45.482780@kamelfreund.de>

John W. Krahn wrote at Fri, 23 May 2003 17:28:53 +0000:

> Everything after the last '/'.
> 
> perl -lpi.bak -e's!(?<=/)[^/]*$!!' temp1.txt

Or
  perl -lpi.bak -e's!(.*/).*/$1/' temp1.txt

what is a bit shorter and you don't need to know anything about negative
look behind.


Greetings,
Janek


------------------------------

Date: 23 May 2003 14:14:17 -0700
From: ramc8191@rediffmail.com (ram)
Subject: Re: removing last part of a line
Message-Id: <53c2d1ac.0305231314.6e7b80f5@posting.google.com>

> perl -pi.bak -e 's/\/.*//' temp1.txt

Thanks a lot guys..
just beginning to understand the power of perl


------------------------------

Date: Fri, 23 May 2003 16:54:09 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: removing last part of a line
Message-Id: <Xns9384B60AE9FFFsdn.comcast@216.166.71.239>

"John W. Krahn" <krahnj@acm.org> wrote in news:3ECE5A43.F8D1AC6E@acm.org:

> Everything after the first '/'.
> 
> perl -pi.bak -e's!(?<=/).*!!' temp1.txt

Why so complex?  Imho, negative lookbehind assertions are for unusual 
cases.  Why not simply

    s!/.*!/!;

 
> Everything after the last '/'.
> 
> perl -lpi.bak -e's!(?<=/)[^/]*$!!' temp1.txt

Why not simply s!/[^/]*$!/! ?

-- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print


------------------------------

Date: Fri, 23 May 2003 23:14:38 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: removing last part of a line
Message-Id: <3ECEAB4C.FE6D0F3D@acm.org>

Janek Schleicher wrote:
> 
> John W. Krahn wrote at Fri, 23 May 2003 17:28:53 +0000:
> 
> > Everything after the last '/'.
> >
> > perl -lpi.bak -e's!(?<=/)[^/]*$!!' temp1.txt
> 
> Or
>   perl -lpi.bak -e's!(.*/).*/$1/' temp1.txt

Substitution pattern not terminated at -e line 1.


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5031
***************************************


home help back first fref pref prev next nref lref last post