K
Kim Gardiner CS2003
Can you issue UNIX commands using Perl?
Thanks.
Thanks.
Can you issue UNIX commands using Perl?
Thanks.
Kim said:Can you issue UNIX commands using Perl?
Kim said:Can you issue UNIX commands using Perl?
Kim Gardiner CS2003 said:Can you issue UNIX commands using Perl?
Kim said:Can you issue UNIX commands using Perl?
You can, but it's often a bad idea.
Some folks treat Perl like a glorified korn shell, and do ghastly
things like this:
my @data = `cat somefile.txt`;
or
my @files = `ls /some/directory`;
Perl has built-in functions for a lot of stuff you might be tempted to
use shell commands for. It's generally preferable to use Perl when you
write Perl programs.
tfe said:Kim Gardiner CS2003 ha escrito:
Sure and "there is more than one way to do it" ...
qx! command with args!;
system("Command","arg1","arg2",...);
`command with args`
open(PIPE, "command |");
Warren said:Even if it doesn't, you can still issue them.
Because 1) it's inefficient in that you are forking and exec'ing aJohn said:Depends on what you're doing of course. Why would I copy a program
that does already its work perfectly and reinvent the wheel? Increase
development time, and make many mistakes while doing so?
Andrew DeFaria said:Because 1) it's inefficient in that you are forking and exec'ing a
process to do it
and 2) portability
- there's no guarantee that the
next platform you port this to has the same commands.
For example, you
use "ls" above.
But there is no "ls" under Windows.
If instead you use
a more Perl like way your Perl script will immediately port without
and issue.
As is comment it depends. When you automate your build system with sayAbigail said:If I'm willing to pay the price of running anything in Perl, do you
really thing I can be bothered about the overhead of forking? If the
time constraints where that critical, the error would have been
writing the program in Perl, not the forking. Then it should have been
written in C instead.
You have yet to write a program that could be ported to Windows would be__ process to do it and 2) portability - there's no guarantee that the
next
__ platform you port this to has the same commands. For example, you use
I've been programming Perl for over 12 years. I've yet to write a
program that had to be ported to Windows.
Sounds to me like you are just inexperienced in the area. I do it allI did once had to port a long shell/awk/SQL script (over 1000 lines)
from Solaris to Windows. After installing a Unix toolkit the script
only required a single change: the location of the temp directory.
I've found more porting issues between different versions of Perl (not
to mention different versions of CPAN modules) than between different
UNIX toolkits (just keep yourself away from all the fancy GNU/Linux
features if you have the need to run it on a real UNIX). After all,
there's POSIX while there isn't a Perl standard.
So you've never seen a Perl script run on Windows have you? My god your__ "ls" above. But there is no "ls" under Windows. If instead you use a
__ more Perl like way your Perl script will immediately port without
and issue.
Really? Last time I looked Windows didn't come with perl either.
Andrew DeFaria said:Taking the poor grammar out of the picture
Similarly I think it's better to write script in anticipation that
they may be asked to run on systems I've never thought that they
would.
server, grep, awk, diff and quite literally thousands of others, I
cannot guarantee that the client will go for it. Indeed many do not.
Yes and many of them can't because they use things like those
described above.
My Perl scripts can and are used on various platforms.
And if the client will allow you to install such tools (and upkeep,
patch, update, etc.). This is not always the case in the real world.
Additionally it adds to the requirements and prerequisites for the
usage of your tool - not a good thing.
Finally often the external tool
does a lot more stuff than what you need. They call this wasteful.
Again this is good to know. I always like knowing who I would *not*
recommend for a job. Welcome to the list.
Exactly is a debatable term here.
Think about how hard perl -MCPAN
My point is, if 10,000 accesses are required, strapping them withAbigail said:Bleh. If you do 10,000 calls to 'ls' and it's slow, then it's the disk
access that's the bottleneck, not the forks.
Probably is - however I didn't say that. So if you wish to argue yourAnd even ten, saying "if you do it 10,000 times, it's slow, so you
should never use it" is sillyness.
No my argument is that you shouldn't do 10,000 fork/execs to grep to doIf your program does 10,000 regex matches and it's slow because of
that, do you draw the conclusion you should
never use a regex because doing 10,000 of them might form a bottleneck
in some program?
And as I can see you are extremely open minded! Bravo!No. I don't do Windows and I've never done Windows. And I don't apply
for jobs that involve doing anything on Windows.
Could that be because they all have their heads as far up their asses asGood for you. I typically work in environments where if the
environment would need to be ported, it would take a lot of people
several years to do it
Listen sonny, I've probably worked at far more companies than you, many(and the only time I worked for a company where the company decided to
port their product to Windows they abandoned their effort after 18
months, as they found out their customers weren't interested). If it
were to be done, any program would have to be modified anyway.
Actually many times I've ported my programs and tools to Unix too!Yes, and? Just because you have to port your programs to Windows,
You just go ahead and stick your little head back into that ground anddoesn't mean I have to restrict myself and not to use the excellent
tools any Unix system gives me.
Granted! Hey I'm a firm advocate on usage of Cygwin. In fact I'd jumpI've seen Perl scripts on Windows. And I've seen 'ls' on Windows as
well. And 'cat'. And 'echo'. And every other common Unix tool. Unix
tools have been ported to Windows. More than once even.
If I'm asked to write a Perl script by the client then assuming there'llI'm just saying that if you want to use the argument that certain
tools aren't standard on Windows, you should consider that perl isn't
standard either.
Andrew DeFaria said:Abigail wrote:
[..]
Probably is - however I didn't say that. So if you wish to argue yourAnd even ten, saying "if you do it 10,000 times, it's slow, so you
should never use it" is sillyness.
own made up things I guess I can't stop you. But the only thing silly
here is your strawman.Because 1) it's inefficient in that you are forking and exec'ing a= John Bokma wrote: = Andrew DeFaria
Depends on what you're doing of course. Why would I copy a program
that does already its work perfectly and reinvent the wheel? Increase
development time, and make many mistakes while doing so?
process to do it and 2) portability - there's no guarantee that the >
next platform you port this to has the same commands. For example, you
use "ls" above. But there is no "ls" under Windows. If instead you use
a more Perl like way your Perl script will immediately port without
and issue.
No my argument is that you shouldn't do 10,000 fork/execs to grep to
do these regex matches - you should do them internally as that's more
efficient.
And as I can see you are extremely open minded! Bravo!
Listen sonny, I've probably worked at far more companies than you,
the real world and while ls, cat, echo, etc. can be installed on a
Windows box often it isn't.
we were talking about Perl, remember?) seems to me to be stupid, short
sighted, lazy, etc.
hubris said:If I'm asked to write a Perl script by the client then assuming
there'll be a Perl interpreter is not a silly assumption.
What an argument to authority?!? Apparently you are also in the "let'sCharlton said:You *really* ought to do enough research to find out who you're
lecturing. I don't think you intend this tirade to come across as comedy.
Andrew DeFaria said:Which rigid rule are you referring to since I made no such claim. I
gave reasons why I thought it was better to do X than Y not that one
had to do X instead of Y. Can you understand that logical difference?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.