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

Re: System call in Windows

by krusty (Hermit)
on Oct 24, 2008 at 19:33 UTC ( [id://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?

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.

    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 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found