Current location: Hot Scripts Forums » Programming Languages » Perl » Perl subsititution on Windows


Perl subsititution on Windows

Reply
  #1 (permalink)  
Old 07-20-09, 09:20 PM
kenkanya kenkanya is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Perl subsititution on Windows

OS: Windows XP SP3
Perl: Perl 5.10

Iam a newbie in perl scripting.
(I have written small perl simple string changes earlier.)
eg:
perl -pi.bak -e "
s|myword=oldworld|myword=newword|g" myfile.txt


My config.prop file contains the line

windowsdrivestocrawl=n:/fdm9_84919_c347|j:/fdm9_84919_c347|w:/fdm9_84919_c347_2

which i want to change to
windowsdrivestocrawl=w:/fdm9_84919_c347_2


My windows batch script (mybatch.bat) contains scripts for copying one folder to another folder in mapped drives. After copying those folders (including files - like config.prop), iam making changes in those files by calling perl.

mybatch.bat
xcopy d:\allfolders\*.* n:\
perl -pi.bak -e"
<followed by changes to be made in file config.prop>

But this file config.prop contains information as show in start of the thread.

Following code suggested by experts on how to use it for subsititution of string.
Can anyone let me know how to go further?

____________
you are on windows with Perl installation, therefore, use Perl. No need for batch.

--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------

while(<>){
chomp;
if ( /windowsdrivestocrawl=/){
# do the substitution
}
print $_ ."\n"; }

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


on the command line or in your batch

--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------

perl myperlscript.pl configfile
____________

So as far as the above script concerns, should i say it should be
while(<>){
chomp;
if ( /windowsdrivestocrawl=/){
w:/fdm9_84919_c347_2
}
print $_ ."\n"; }

and just run this
perl myperlscript.pl configfile.prop
and this will make the changes in the file? Or correct me if iam wrong.

Or this can be included in batch script (mybatch.bat - as shown below), is this correct?


mybatch.bat #start of batch file
xcopy d:\allfolders\*.* n:\
perl myperlscript.pl configfile.prop
#end of batch file

So this batch script will inturn call the perl script for subsititution?

Do also provide me the links for perl tutorials. I also found this perltutorial.org
Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-21-09, 02:39 PM
Boraan's Avatar
Boraan Boraan is offline
Coding Addict
 
Join Date: Jul 2007
Location: Clayton, NC
Posts: 292
Thanks: 0
Thanked 1 Time in 1 Post
are you trying to do the job in a batch file or a perl script? You have the right code already you just need to decide which way you want to do it?

if you're going to use it in a batch file then you will need to format the code with perl execute so the system knows it's perl code that's following, otherwise windows will try to interpret it as shell commands.

I would not use a batch however. Batch files are made for automation, usually unattended. the <> in the perl code denotes a user input
__________________
Dexter Nelson
Techdex Development & Solutions
========================
Internet Marketing For Programmers | Free Market Research in 15 Minutes or Less
My Software: Hotscripts Softpedia software.techdex.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-28-09, 12:41 AM
kenkanya kenkanya is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Boraan View Post
are you trying to do the job in a batch file or a perl script? You have the right code already you just need to decide which way you want to do it?

if you're going to use it in a batch file then you will need to format the code with perl execute so the system knows it's perl code that's following, otherwise windows will try to interpret it as shell commands.

I would not use a batch however. Batch files are made for automation, usually unattended. the <> in the perl code denotes a user input
Ok. Thanks Borran.
I will not be using in batch as you said. Will run it as separate perl script.
Now what is the next step
If <> is the user input, then how do i go about?
I only want to replace the windowsdrivetorecrawl with w:/fdm9_84919_c347_2
and this would be static. So no need of user input.
How do i run this script?

Sorry for the late reply (was not feelig well and then held up with other problems)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-28-09, 01:23 AM
kenkanya kenkanya is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
When i run the above script (put it in a file firstperl.pl) i get the following message.

D:\myfold>perl firstperl.pl configfile
Search pattern not terminated at firstperl.pl line 6.

firstperl.pl contains
while(<>){
chomp;
if ( /windowsdrivestocrawl=/){
w:/fdm9_84919_c347_2
}
print $_ ."\n";
}

can you let me know, what iam missing?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 04:27 AM
Count requesters from an apache log file ddolddolee82 Perl 1 03-17-06 04:08 AM
Perl FormMail Problem ennanguyen2002 Perl 2 03-09-05 05:47 PM
Cannot user wildcard in Perl under windows XP bruceleung2000 Perl 2 01-23-05 02:12 PM
Matrix Reseller - Windows 2003 and FreeBSD vortech General Advertisements 0 11-02-03 11:06 PM


All times are GMT -5. The time now is 01:15 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.