Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 '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?

Replies are listed 'Best First'.
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.


    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 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!
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://719412]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2018-01-19 11:50 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (217 votes). Check out past polls.