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

Re: System call in Windows

by krusty (Hermit)
on Oct 24, 2008 at 19:33 UTC ( #719412=note: print w/ replies, xml ) Need Help??


in reply to System call in Windows

Try the following:

#!/usr/bin/perl while (<>){ s/CAT/mouse/g; print; }

Then run the code like so:
prompt> perl -w myscript.pl 'D:\tmp\file.txt' > D:\tmp\file.txt

Update: Thanks for the reference to the -pi flags. I understand now. The while loop is superfluous with the -p and the -i will edit the file given in place. Why does he need a system() function call around the whole thing? Won't that spawn another shell?


Comment on Re: System call in Windows
Select or Download Code
Re^2: System call in Windows
by runrig (Abbot) on Oct 24, 2008 at 19:37 UTC
    If the OP fixed the quoting, then the file would be opened, read, and written to. Look at the -p and -i options in perlrun.

    Update:

    Won't that spawn another shell?

    Yes, and you could do it without spawning another shell, with a bit more code. But the -p and -i flags make the job convenient, and if the OP doesn't care about the extra process, then neither do I :-)

Re^2: System call in Windows
by NateTut (Deacon) on Oct 24, 2008 at 19:54 UTC
    I myself wouldn't have wanted the overhead of a system call to start another perl interpreter, but it sounded like the OP was porting over something that had worked in UNIX to WinDoze, so I answered his basic question about that.
Re^2: System call in Windows
by csarid (Sexton) on Oct 24, 2008 at 19:58 UTC
    Hello krusty,
    Thanks for the suggestion. It's a good work around and I'll definitely use it in some other case. But what part of what I'm trying to do is also provide variables in the replacement so instead of CAT and mouse I would have "$var1" and "$var2".
    Thanks again!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-12-26 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (174 votes), past polls