[16187] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3599 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 19:14:06 2000

Date: Mon, 10 Jul 2000 16:13:52 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963270832-v9-i3599@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 10 Jul 2000     Volume: 9 Number: 3599

Today's topics:
        Simple Reg Expression Question <kennylim@techie.net>
        Simple Reg Expression Question <kennylim@techie.net>
        Simple Reg Expression Question <kennylim@techie.net>
    Re: Simple Reg Expression Question <debjit@oyeindia.com>
    Re: Simple Reg Expression Question <yosikim@lgeds.lg.co.kr>
    Re: Simple Reg Expression Question (Keith Calvert Ivey)
    Re: Simple Reg Expression Question <kennylim@techie.net>
    Re: Simple Reg Expression Question (Abigail)
    Re: Simple Reg Expression Question <kennylim@techie.net>
    Re: Simple Reg Expression Question (Bernard El-Hagin)
    Re: Simple Reg Expression Question <adetalabi@clara.co.uk>
    Re: Simple Reg Expression Question (Bernard El-Hagin)
    Re: Simple Reg Expression Question (Keith Calvert Ivey)
    Re: Simple Reg Expression Question <kennylim@techie.net>
        Simple script works on Unix,  but can anyone get it to  (Ariel Lia)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 03 Jul 2000 20:15:33 GMT
From: "Kenny Lim" <kennylim@techie.net>
Subject: Simple Reg Expression Question
Message-Id: <Fv685.31392$_b3.782466@newsread1.prod.itd.earthlink.net>


Hi All,

I am searching through *.cpp and *.rgs extension for
pattern matches with the following criteria :

(m/\sProgID\s=\s*s\s'*.)

Example :

ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
ProgID = s 'Explorer.DatabaseSearchWindow.1'
ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'

Problem :

If matches found, We only need to "extract" the "first words" of the
results found after "ProgID = s'[First words]" and convert the version
number
from either with "no version" or from 5 to 52.  (See Example below)

ie.

DatabaseSearch5      ---> to DatabaseSearch52
Explorer  ---> to Explorer52
DB2Explorer5  ---> to DB2Explorer52

#As you can see Explorer have no version and DB2Explorer5 has 2 numbers (2
and 5 within the words)

(a) How do we only extract the first words from the pattern matching found ?
(b) How do we only convert the version number found on the strings given the
inconsistent naming convention as above ?
(c) Results will have to printed out into a physical file.

Please let me know if you need more explicit information.

Any advise would be greatly appreaciated.

Thanks in advance.

Kenny-









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

Date: Wed, 05 Jul 2000 00:20:12 GMT
From: "Kenny Lim" <kennylim@techie.net>
Subject: Simple Reg Expression Question
Message-Id: <0bv85.30741$NP5.897976@newsread2.prod.itd.earthlink.net>

Hi All,

How do we split the following word into 2 separate strings ?

ie.

Explorer42

into

(a)    Explorer as $1
(b)    42 as $2

I would like to be able to print out either just the word or both the word
and the number for search and replace
purposes.

ie.

$search =   {$1}{$2};    <---this should specify "Explorer42"
$replace = "{$1}52";     <---this should specify "Explorer52"

Any advise would be grealy appreciated.

Thanks in Advance.

Kenny-






If you are interested,  Enclosed here is the snippet of my code [So far I am
able to only change the words that I had hardcoded
and not from the original format found to the new format]


#! /usr/local/bin/perl -w
use File::Copy;
use File::Find;


$Directory = "c:/perl/work/vss/sh3/"; #home
#$Directory = "d:/vss/vss_test/"; #work
$Cwd = `pwd`;

find (\&scan_Clsid,$Directory);

sub scan_Clsid
{

return unless $_ =~ /\.rgs$|\.cpp$/;

my $orig =  $_;
my $new = \@temp;


open (ORIG,"< $orig") or die "Could not open $orig: $!";
open (NEW, "> $new") or die "Could not open $new: $!";



 while (<ORIG>)
 {
  chomp;

   if (m/^\s*ProgID\s*=\s*s\s*'(\w+?)\d*\./g)
  {
  print "$search|$replace\n";
  $search = "${1}5";
  $replace = "${1}52";

     s/$search/$replace/g;
  print NEW;

  }


        close (ORIG);
        close (NEW);

       move ($new, $orig);

}
}














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

Date: Wed, 05 Jul 2000 00:25:41 GMT
From: "Kenny Lim" <kennylim@techie.net>
Subject: Simple Reg Expression Question
Message-Id: <9gv85.30750$NP5.898452@newsread2.prod.itd.earthlink.net>


Hi All,

 How do we split the following word into 2 separate strings ?

 ie.

 Explorer42

 into

 (a)    Explorer as $1
(b)    42 as $2

 I would like to be able to print out either just the word or both the word
and the number for search and replace
purposes.

 ie.

 $search =   {$1}{$2};    <---this should specify "Explorer42"
$replace = "{$1}52";     <---this should specify "Explorer52"

 Any advise would be grealy appreciated.

 Thanks in Advance.

 Kenny-


 If you are interested,  Enclosed here is the snippet of my code [So far I
am
able to only change the words that I had hardcoded
and not from the original format found to the new format]


 #! /usr/local/bin/perl -w
use File::Copy;
use File::Find;


 $Directory = "c:/perl/work/vss/sh3/"; #home
#$Directory = "d:/vss/vss_test/"; #work
$Cwd = `pwd`;

 find (\&scan_Clsid,$Directory);

 sub scan_Clsid

{

 return unless $_ =~ /\.rgs$|\.cpp$/;

 my $orig =  $_;
my $new = \@temp;

 open (ORIG,"< $orig") or die "Could not open $orig: $!";
open (NEW, "> $new") or die "Could not open $new: $!";

while (<ORIG>)

{
chomp;

   if (m/^\s*ProgID\s*=\s*s\s*'(\w+?)\d*\./g)
   {
   print "$search|$replace\n";
   $search = "${1}5";
   $replace = "${1}52";

    s/$search/$replace/g;
   print NEW;

   }


         close (ORIG);
         close (NEW);

        move ($new, $orig);

 }
}
















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

Date: Tue, 4 Jul 2000 10:13:44 +0530
From: "Debjit" <debjit@oyeindia.com>
Subject: Re: Simple Reg Expression Question
Message-Id: <8jsuv6$42b$1@news.vsnl.net.in>

This works(to some extent)
#!/usr/bin/perl -w
open (DATA, 'nodata.txt') or die "cannot open data: $!";
while(<DATA>) {
 if(/^ProgID\s*=\s*s \'(.+?)\./) {
  my $software = $1;
  print $software, "\n";
 }
}
-----nodata.txt-----
ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
ProgID = s 'Explorer.DatabaseSearchWindow.1'
ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'
---------------output---------
DatabaseSearch5
Explorer
DB2Explorer5
---------------------------------


Kenny Lim wrote in message ...
>
>Hi All,
>
>I am searching through *.cpp and *.rgs extension for
>pattern matches with the following criteria :
>
>(m/\sProgID\s=\s*s\s'*.)
>
>Example :
>
>ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
>ProgID = s 'Explorer.DatabaseSearchWindow.1'
>ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'
>
>Problem :
>
>If matches found, We only need to "extract" the "first words" of the
>results found after "ProgID = s'[First words]" and convert the version
>number
>from either with "no version" or from 5 to 52.  (See Example below)
>
>ie.
>
>DatabaseSearch5      ---> to DatabaseSearch52
>Explorer  ---> to Explorer52
>DB2Explorer5  ---> to DB2Explorer52
>
>#As you can see Explorer have no version and DB2Explorer5 has 2 numbers (2
>and 5 within the words)
>
>(a) How do we only extract the first words from the pattern matching found
?
>(b) How do we only convert the version number found on the strings given
the
>inconsistent naming convention as above ?
>(c) Results will have to printed out into a physical file.
>
>Please let me know if you need more explicit information.
>
>Any advise would be greatly appreaciated.
>
>Thanks in advance.
>
>Kenny-
>
>
>
>
>
>
>




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

Date: Tue, 04 Jul 2000 13:54:49 +0900
From: Yongsik Kim <yosikim@lgeds.lg.co.kr>
Subject: Re: Simple Reg Expression Question
Message-Id: <39616E19.4E9E4714@lgeds.lg.co.kr>

while( <DATA> ) {
        m/ProgID\s=\s*s\s'(\w+)\.*/;
        $m = $1;
        $m =~ s/5$/52/;
        $m =~ s/[a-zA-Z]$/52/;
        print "$m\n";
}
__END__
ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
ProgID = s 'Explorer.DatabaseSearchWindow.1'
ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'

Kenny Lim wrote:
> 
> Hi All,
> 
> I am searching through *.cpp and *.rgs extension for
> pattern matches with the following criteria :
> 
> (m/\sProgID\s=\s*s\s'*.)
> 
> Example :
> 
> ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
> ProgID = s 'Explorer.DatabaseSearchWindow.1'
> ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'
> 
> Problem :
> 
> If matches found, We only need to "extract" the "first words" of the
> results found after "ProgID = s'[First words]" and convert the version
> number
> from either with "no version" or from 5 to 52.  (See Example below)
> 
> ie.
> 
> DatabaseSearch5      ---> to DatabaseSearch52
> Explorer  ---> to Explorer52
> DB2Explorer5  ---> to DB2Explorer52
> 
> #As you can see Explorer have no version and DB2Explorer5 has 2 numbers (2
> and 5 within the words)
> 
> (a) How do we only extract the first words from the pattern matching found ?
> (b) How do we only convert the version number found on the strings given the
> inconsistent naming convention as above ?
> (c) Results will have to printed out into a physical file.
> 
> Please let me know if you need more explicit information.
> 
> Any advise would be greatly appreaciated.
> 
> Thanks in advance.
> 
> Kenny-


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

Date: Tue, 04 Jul 2000 14:01:34 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Simple Reg Expression Question
Message-Id: <3961ec03.50361457@nntp.idsonline.com>

Yongsik Kim <yosikim@lgeds.lg.co.kr> wrote:

>while( <DATA> ) {
>        m/ProgID\s=\s*s\s'(\w+)\.*/;
>        $m = $1;
>        $m =~ s/5$/52/;
>        $m =~ s/[a-zA-Z]$/52/;
>        print "$m\n";
>}
>__END__
>ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
>ProgID = s 'Explorer.DatabaseSearchWindow.1'
>ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'

    while (<DATA>) {
        print "${1}52\n" if /^\s*ProgID\s*=\s*s\s*'(\w+?)\d*\./;
    }

Besides being shorter, that avoids printing leftover values of
$1 when the line doesn't match your first regex.  Also, the
original poster didn't say that all the version numbers were 5.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Tue, 04 Jul 2000 22:31:14 GMT
From: "Kenny Lim" <kennylim@techie.net>
Subject: Re: Simple Reg Expression Question
Message-Id: <SAt85.34467$_b3.895258@newsread1.prod.itd.earthlink.net>

Hi Keith,

Thanks for the pointers, the only problem that I am facing
with your given reg exp is I am unable to have the complete
first string with the number for my original format.

ie.

${1}52 = Explorer52 ----> New project Name had been replaced by 52.

Problem :

but I will also need to have the original value which supposed to be

Explorer5, by just printing out {$1} will only provide the character words
ie. Explorer  and not the old version number.
(which there could be any or no project version)

#==================================================================

Ultimately, I am just trying to find the pattern matching and replace all
the older version project name found
with 52. (Disregard to it's original version) My current implementation is
to print out the old and new result
set separated by "|" into a physical log file.

ie.

Explorer5|Explorer52

And then do a search and replace on the old and new words found in the
physical log file.
(Therefore, it is essential to have the original and the new format)

If you have a more efficient approach, it would be very nice of you to share
some of your
thoughts with me.

Thanks in advance.

Kenny-

"Keith Calvert Ivey" <kcivey@cpcug.org> wrote in message
news:3961ec03.50361457@nntp.idsonline.com...
> Yongsik Kim <yosikim@lgeds.lg.co.kr> wrote:
>
> >while( <DATA> ) {
> >        m/ProgID\s=\s*s\s'(\w+)\.*/;
> >        $m = $1;
> >        $m =~ s/5$/52/;
> >        $m =~ s/[a-zA-Z]$/52/;
> >        print "$m\n";
> >}
> >__END__
> >ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
> >ProgID = s 'Explorer.DatabaseSearchWindow.1'
> >ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'
>
>     while (<DATA>) {
>         print "${1}52\n" if /^\s*ProgID\s*=\s*s\s*'(\w+?)\d*\./;
>     }
>
> Besides being shorter, that avoids printing leftover values of
> $1 when the line doesn't match your first regex.  Also, the
> original poster didn't say that all the version numbers were 5.
>
> --
> Keith C. Ivey <kcivey@cpcug.org>
> Washington, DC
>
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
>




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

Date: 04 Jul 2000 22:57:47 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Simple Reg Expression Question
Message-Id: <slrn8m5a31.59a.abigail@alexandra.delanet.com>

Kenny Lim (kennylim@techie.net) wrote on MMD September MCMXCIII in
<URL:news:9gv85.30750$NP5.898452@newsread2.prod.itd.earthlink.net>:
[] 
[] my $new = \@temp;
[] open (NEW, "> $new") or die "Could not open $new: $!";


That is going to be one odd filename.



Abigail
-- 
perl -Mstrict -we '$_ = "goto R.print chop;\n=rekcaH lreP rehtona tsuJ";R1:eval'


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

Date: Wed, 05 Jul 2000 05:44:59 GMT
From: "Kenny Lim" <kennylim@techie.net>
Subject: Re: Simple Reg Expression Question
Message-Id: <vXz85.31257$NP5.922995@newsread2.prod.itd.earthlink.net>

Hi Tony,

My explicit requirement would be able to split
the words and numbers. (the number to be split has
to be only the last 2 digits from the right)

ie.

DB2Explorer52

Words  : DB2Explorer <---As you can see, DB2 also comprise numbers which we
will avoid splitting.
Numbers : 52

Split to :

${1} = Words
${2} = numbers


Would that be possible ? Any pointers would be appreciated.

Thanks in advance.

Kenny-





"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87aefxto5a.fsf@limey.hpcc.uh.edu...
> >> On Wed, 05 Jul 2000 00:20:12 GMT,
> >> "Kenny Lim" <kennylim@techie.net> said:
>
> > Hi All, How do we split the following word into 2
> > separate strings ?
>
> > ie.
>
> > Explorer42
>
> > into
>
> > (a) Explorer as $1 (b) 42 as $2
>
> If you want a straight line, just take 2 points.
>
> But seriously, what are your criteria for splitting the
> string into components?
>
>     word-number?
>
>     anything non digit-number?
>
>     8 characters-rest?
>
> Some more examples would help to remove the ambiguity.
>
> t
> --
> "With $10,000, we'd be millionaires!"
>                                            Homer Simpson
>




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

Date: Wed, 05 Jul 2000 06:36:38 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Simple Reg Expression Question
Message-Id: <slrn8m5lja.gk1.bernard.el-hagin@gdndev25.lido-tech>

On Wed, 05 Jul 2000 05:44:59 GMT, Kenny Lim <kennylim@techie.net> wrote:
>Hi Tony,
>
>My explicit requirement would be able to split
>the words and numbers. (the number to be split has
>to be only the last 2 digits from the right)

Your requirements are still a bit unclear, but if your string *always*
ends in two digits then you can use:

#!/usr/bin/perl -w
use strict;

my $string = "D4512Explorer42";
(my $beginning, my $last_two_digits) = $string =~ /^(.*)(\d\d)$/;
print "$beginning\t$last_two_digits\n";

This yields:

D4512Explorer	42


Bernard
--
${qq=\x22=}=qq=\053=;$_="BeJUST_ANOTHERnaPERL_HACKERd\n";${qq=\x2c=}=qq=\x72=;
print split /[AC-Z_]$"/;


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

Date: Wed, 05 Jul 2000 09:49:08 +0100
From: Ade Talabi <adetalabi@clara.co.uk>
Subject: Re: Simple Reg Expression Question
Message-Id: <3962F684.458809F0@clara.co.uk>

Kenny Lim wrote:
> 
> Hi All,
> 
> I am searching through *.cpp and *.rgs extension for
> pattern matches with the following criteria :
> 
> (m/\sProgID\s=\s*s\s'*.)
> 
> Example :
> 
> ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
> ProgID = s 'Explorer.DatabaseSearchWindow.1'
> ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'
> 
> Problem :
> 
> If matches found, We only need to "extract" the "first words" of the
> results found after "ProgID = s'[First words]" and convert the version
> number
> from either with "no version" or from 5 to 52.  (See Example below)
> 
> ie.
> 
> DatabaseSearch5      ---> to DatabaseSearch52
> Explorer  ---> to Explorer52
> DB2Explorer5  ---> to DB2Explorer52
> 
> #As you can see Explorer have no version and DB2Explorer5 has 2 numbers (2
> and 5 within the words)
> 
> (a) How do we only extract the first words from the pattern matching found ?
> (b) How do we only convert the version number found on the strings given the
> inconsistent naming convention as above ?
> (c) Results will have to printed out into a physical file.
> 
> Please let me know if you need more explicit information.
> 
> Any advise would be greatly appreaciated.
> 
> Thanks in advance.
> 
> Kenny-


Use the dot(.) to split the variable, look 'reversely' and add 52 to
none-5ers, and 2 if you find 5 at the end.
-- 
We see, whatever we want to see, whether visible or not 
- AT. June 2000.


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

Date: Wed, 05 Jul 2000 10:28:32 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Simple Reg Expression Question
Message-Id: <slrn8m6363.gk1.bernard.el-hagin@gdndev25.lido-tech>

On Wed, 05 Jul 2000 09:49:08 +0100, Ade Talabi <adetalabi@clara.co.uk> wrote:
>Kenny Lim wrote:
>> 
>> Hi All,
>> 
>> I am searching through *.cpp and *.rgs extension for
>> pattern matches with the following criteria :
>> 
>> (m/\sProgID\s=\s*s\s'*.)
>> 
>> Example :
>> 
>> ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
>> ProgID = s 'Explorer.DatabaseSearchWindow.1'
>> ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'
>> 
>> Problem :
>> 
>> If matches found, We only need to "extract" the "first words" of the
>> results found after "ProgID = s'[First words]" and convert the version
>> number
>> from either with "no version" or from 5 to 52.  (See Example below)
>> 
>> ie.
>> 
>> DatabaseSearch5      ---> to DatabaseSearch52
>> Explorer  ---> to Explorer52
>> DB2Explorer5  ---> to DB2Explorer52
>> 
>> #As you can see Explorer have no version and DB2Explorer5 has 2 numbers (2
>> and 5 within the words)
>> 
>> (a) How do we only extract the first words from the pattern matching found ?

If you want to find everything up to the first "." use the character
class [^.] (everything except a ".") with a quantifier.

>> (b) How do we only convert the version number found on the strings given the
>> inconsistent naming convention as above ?

See below.

>> (c) Results will have to printed out into a physical file.

See below.

Here's an ugly, but working solution:

#!/usr/bin/perl -w
use strict;

open (OUT, "> /output/file") or die "Can't coz $!\n";

while (<DATA>){
	(my $word) = $_ =~ m/^ProgID = s '([^.]*)\..*$/;
	$word =~ m/^\w*(\d|\w)$/;
	if ($1 =~ /\d/){
		$word =~ s/$/2/;
	}
	else{
		$word =~ s/$/52/;
	}
	print OUT $word, "\n";
}

__DATA__
ProgID = s 'DatabaseSearch5.DatabaseSearchWindow.1'
ProgID = s 'Explorer.DatabaseSearchWindow.1'
ProgID = s 'DB2Explorer5.DatabaseSearchWindow.1'

This results in the following three lines being written to the specified
output file:

DatabaseSearch52
Explorer52
DB2Explorer52

I *think* that's what you wanted.

Bernard
--
perl -e '${qq=\x22=}=qq=\053=;$_="BeJUST_ANOTHERnaPERL_HACKERd\n";
${qq=\x2c=}=qq=\x72=;print split /[AC-Z_]$"/;'


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

Date: Wed, 05 Jul 2000 12:40:31 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Simple Reg Expression Question
Message-Id: <3964a5cf.3386026@nntp.idsonline.com>

"Kenny Lim" <kennylim@techie.net> wrote:

> I would like to be able to print out either just the word or
>both the word and the number for search and replace purposes.

I don't understand why you need this.  Just do the search and
replace when you do the match.

[snip]
> #! /usr/local/bin/perl -w
>use File::Copy;
>use File::Find;
>
> $Directory = "c:/perl/work/vss/sh3/"; #home
>#$Directory = "d:/vss/vss_test/"; #work

Looks good so far.  It's especially good that you're using -w
and that you know to use backslashes even when you're on a
Windows system.  You are missing "use strict;", though.

>$Cwd = `pwd`;

What's that for?  You don't use it.

> find (\&scan_Clsid,$Directory);
>
> sub scan_Clsid

Why the bizarre capitalization?

>{
>
> return unless $_ =~ /\.rgs$|\.cpp$/;

Drop the "$_ =~ " -- using it defeats the whole point of $_.
In fact, just write

    return unless /\.(?:rgs|cpp)$/;

> my $orig =  $_;
>my $new = \@temp;
>
> open (ORIG,"< $orig") or die "Could not open $orig: $!";
>open (NEW, "> $new") or die "Could not open $new: $!";

Good that you're checking the return values of your open()s.
But why are you using a stringified array reference as a file
name?

>while (<ORIG>)
>
>{
>chomp;

You don't want to chomp, because you're printing the line out to
a file later on and will need the newline.

>   if (m/^\s*ProgID\s*=\s*s\s*'(\w+?)\d*\./g)
>   {
>   print "$search|$replace\n";
>   $search = "${1}5";
>   $replace = "${1}52";
>
>    s/$search/$replace/g;
>   print NEW;
>
>   }

The /g modifier on your regex is unnecessary, because it can't
match more than once on a line (the ^ will match only at the
beginning).

But the main problem with this section is that you're doing the
replacement in a very roundabout way.  You can do the same thing
with this:

   s/^(\s*ProgID\s*=\s*s\s*'\w+?)\d*\./${1}52./;
   print NEW;

I'm assuming you really want to print nonmatching lines to the
new file unchanged.  Your program leaves them out.

My version also doesn't print the search and replace strings to
STDOUT.  Yours prints them before they've been set.  If you
really need to print something like that, you'll need some extra
capturing parentheses:

   s/^(\s*ProgID\s*=\s*s\s*'(\w+?))(\d*)\./${1}52./;
   print NEW;
   print "$2$3 --> ${2}52\n";

>         close (ORIG);
>         close (NEW);
>
>        move ($new, $orig);

You're closing the files after processing only one line.  The
ending bracket below should come before you close them.

> }
>}


-- 
Keith C. Ivey <kcivey@cpcug.org>, Washington, DC
(Still working on getting the newsfeeds.com obscenity below removed.
And isn't it mind-bogglingly stupid to claim 80,000 newsgroups
simply because you newgroup every typo or joke that comes along?)


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Thu, 06 Jul 2000 07:39:32 GMT
From: "Kenny Lim" <kennylim@techie.net>
Subject: Re: Simple Reg Expression Question
Message-Id: <UIW85.34674$NP5.1052412@newsread2.prod.itd.earthlink.net>

Hey Guys,

With the help I had received, the problem is now resolved.

Thanks for all the great pointers.  Cheers !

Kenny-


"Keith Calvert Ivey" <kcivey@cpcug.org> wrote in message
news:3964a5cf.3386026@nntp.idsonline.com...
> "Kenny Lim" <kennylim@techie.net> wrote:
>
> > I would like to be able to print out either just the word or
> >both the word and the number for search and replace purposes.
>
> I don't understand why you need this.  Just do the search and
> replace when you do the match.
>
> [snip]
> > #! /usr/local/bin/perl -w
> >use File::Copy;
> >use File::Find;
> >
> > $Directory = "c:/perl/work/vss/sh3/"; #home
> >#$Directory = "d:/vss/vss_test/"; #work
>
> Looks good so far.  It's especially good that you're using -w
> and that you know to use backslashes even when you're on a
> Windows system.  You are missing "use strict;", though.
>
> >$Cwd = `pwd`;
>
> What's that for?  You don't use it.
>
> > find (\&scan_Clsid,$Directory);
> >
> > sub scan_Clsid
>
> Why the bizarre capitalization?
>
> >{
> >
> > return unless $_ =~ /\.rgs$|\.cpp$/;
>
> Drop the "$_ =~ " -- using it defeats the whole point of $_.
> In fact, just write
>
>     return unless /\.(?:rgs|cpp)$/;
>
> > my $orig =  $_;
> >my $new = \@temp;
> >
> > open (ORIG,"< $orig") or die "Could not open $orig: $!";
> >open (NEW, "> $new") or die "Could not open $new: $!";
>
> Good that you're checking the return values of your open()s.
> But why are you using a stringified array reference as a file
> name?
>
> >while (<ORIG>)
> >
> >{
> >chomp;
>
> You don't want to chomp, because you're printing the line out to
> a file later on and will need the newline.
>
> >   if (m/^\s*ProgID\s*=\s*s\s*'(\w+?)\d*\./g)
> >   {
> >   print "$search|$replace\n";
> >   $search = "${1}5";
> >   $replace = "${1}52";
> >
> >    s/$search/$replace/g;
> >   print NEW;
> >
> >   }
>
> The /g modifier on your regex is unnecessary, because it can't
> match more than once on a line (the ^ will match only at the
> beginning).
>
> But the main problem with this section is that you're doing the
> replacement in a very roundabout way.  You can do the same thing
> with this:
>
>    s/^(\s*ProgID\s*=\s*s\s*'\w+?)\d*\./${1}52./;
>    print NEW;
>
> I'm assuming you really want to print nonmatching lines to the
> new file unchanged.  Your program leaves them out.
>
> My version also doesn't print the search and replace strings to
> STDOUT.  Yours prints them before they've been set.  If you
> really need to print something like that, you'll need some extra
> capturing parentheses:
>
>    s/^(\s*ProgID\s*=\s*s\s*'(\w+?))(\d*)\./${1}52./;
>    print NEW;
>    print "$2$3 --> ${2}52\n";
>
> >         close (ORIG);
> >         close (NEW);
> >
> >        move ($new, $orig);
>
> You're closing the files after processing only one line.  The
> ending bracket below should come before you close them.
>
> > }
> >}
>
>
> --
> Keith C. Ivey <kcivey@cpcug.org>, Washington, DC
> (Still working on getting the newsfeeds.com obscenity below removed.
> And isn't it mind-bogglingly stupid to claim 80,000 newsgroups
> simply because you newgroup every typo or joke that comes along?)
>
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----




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

Date: Thu, 6 Jul 2000 14:15:21 -0400
From: Ariellia@garden.com (Ariel Lia)
Subject: Simple script works on Unix,  but can anyone get it to work on NT/IIS ? - edittag.zip [0/1]
Message-Id: <ABA662181900A673.5C9A8016A2C15D36.E1931AF7FFAC5C2D@lp.airnews.net>

Hello,

Attached is a very simple script that I know works on Unix, and the  
author says it works on NT/IIS, but I am a perl newbie, at least on NT.

This script let users edit an html page online.  The simple instructions 
are attached...I just think I'm missing some NT relevant syntax in the 
perl file...


I get 404 error, file not found when I insert the following into a 
browser pointing to the server on which is installed IIS/Active Perl 613:   
http://192.158.140.116/cgi-bin/edittag.pl  This looks for test.html

I have tried putting the test.html file, and all of the files in:

c:\inetpub\wwwroot\
c:\inetpub\wwwroot\cgi-bin

I have saved the .pl files as .cgi files, so that both .pl and .cgi exist 
together.

All of my file associations are in place:

C:\>assoc cgi
cgi=cgifile

C:\>assoc perl
perl=Perl File

C:\>ftype cgi
cgi=c:\perl\bin\perl.exe %1 %*

C:\>ftype perl
perl=c:\perl\bin\perl.exe %1 %*

IIS is setup to recognize perl scripts.

But I can not get this script to work.  Again, I launch it using 
http://192.158.140.116/cgi-bin/edittag.pl  which is the ipaddress of my 
web server.

I get the opening page, requesting "Insert file to edit-Remember to enter 
a relative path. " and I have tried entering lots of variations here:

test.html
/test.html
\\test.html

c:\inetpub\wwwroot\cgi-bin\test.html
c:/inetpub/wwwroot/cgi-bin/test.html
c:\\inetpub\\wwwroot\\cgi-bin\\test.html
c:\\inetpub\\wwwroot\\test.html  etc etc.

Can anyone get this script to work on NT/IIS?  I know it's just a simple 
configuration problem.

It's such a basic script!

Thanks for your input!!!

Ariel
ariel@thezoo.com


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3599
**************************************


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