Forums » Linux
Merry christmas, guys, I wrote all you folks a tga to jpg converter. Perl.
#!/usr/bin/perl
# (c) 2004 Tyler Denniston
# a simple tool used to convert tga files to jpeg files,
# using pre-existing tools
foreach $arg (@ARGV) {
if (-f $arg) {
`tgatoppm $arg > a`;
`ppmtojpeg a > b`;
($name,$trash) = split (/\./,$arg);
$name .= ".jpg";
`mv b $name`;
`rm -f a`;
}else{
print "$arg does not exist!\n";
}
}
-rc
#!/usr/bin/perl
# (c) 2004 Tyler Denniston
# a simple tool used to convert tga files to jpeg files,
# using pre-existing tools
foreach $arg (@ARGV) {
if (-f $arg) {
`tgatoppm $arg > a`;
`ppmtojpeg a > b`;
($name,$trash) = split (/\./,$arg);
$name .= ".jpg";
`mv b $name`;
`rm -f a`;
}else{
print "$arg does not exist!\n";
}
}
-rc
Merry Christmas, I wrote this last year:
#!/bin/bash
# (c) 2003
mkdir images-`date +%F`
for f in *.tga
do convert $f "$(basename "$f" .tga).jpg"
mv "$(basename "$f" .tga).jpg" images-`date +%F`
test -f "$images-%F/(basename "$f" .tga).jpg" && rm $f || echo Error converting $f
done
#!/bin/bash
# (c) 2003
mkdir images-`date +%F`
for f in *.tga
do convert $f "$(basename "$f" .tga).jpg"
mv "$(basename "$f" .tga).jpg" images-`date +%F`
test -f "$images-%F/(basename "$f" .tga).jpg" && rm $f || echo Error converting $f
done
Download my script and save yourselves the copy+paste.
http://www.roguelazer.com/files/imageconvert
http://www.roguelazer.com/files/imageconvert
Yes, but my script is much easier to understand. Tsk tsk, you seem to have developed the 'hacker' coding style--short, effective, but HELL to maintain...
-rc
-rc
Thankfully, mine needs no maintaining. Yours is actually just a duplication of the "convert" utility found in the imagemagick package. And, since I hate perl and never use it, yours makes as much sense to me as the output of "cat /usr/bin/convert | less"
You...HATE Perl? Oh, my dear child. How they have hurt you... You really should look into it. A very easy to learn language, very powerful, and super cool. I'm serious.
-rc
-rc
perl is write once try to read language
pretty much in the same league that K is.
pretty much in the same league that K is.
Everything perl can do bash can do better. :P Actually, I prefer C to either. The power of bash is in system(). :P
Oh it is. It is. Here's the link:
http://www.forkandspoonsw.com/cgi-bin/dev/code.pl
Have fun!
-rc
http://www.forkandspoonsw.com/cgi-bin/dev/code.pl
Have fun!
-rc
I call your system() with an escape encoded string ;)
I call your escape encoded string with 0111001101111001011100110111010001100101011011010010100000101001
0110000000100100001010000111001001101101001000000010110101100110011100100010000001111110001000000010111100100000001001100010100101100000
Thankfully, you didn't have write privliges on /
no, however system() is dangerous as it allows escaping (unless you filter) and even if you filter somone might do weird things with utf-8 encodings, escape coding and other such "nice" stuffs. *cough*
(Hello Microsoft IIS)
(Hello Microsoft IIS)
That's why I only use system() with hardcoded options. And never, ever, use system() on a program that can be accessed remotely.
edit: fixed a few mistakes
#!/usr/bin/perl
# code.pl
use CGI qw(:standard);
$input=param('input');
if (!$input) {
print "Content-type: text/html\n\n";
print "<html><head><title>Enter code!</title></head>
<body>
<form action=code.pl method=post>
<input name=\"input\" type=text>
<input type=submit value=Submit>
</form>
</body></html>
";
}else{
system("input");
}
How do you like that Rogue? Tee hee.
edit: Hah! Finally figured out how to get spacing.
-rc
#!/usr/bin/perl
# code.pl
use CGI qw(:standard);
$input=param('input');
if (!$input) {
print "Content-type: text/html\n\n";
print "<html><head><title>Enter code!</title></head>
<body>
<form action=code.pl method=post>
<input name=\"input\" type=text>
<input type=submit value=Submit>
</form>
</body></html>
";
}else{
system("input");
}
How do you like that Rogue? Tee hee.
edit: Hah! Finally figured out how to get spacing.
-rc
Cool. Why don't you set that up on your webserver?
hahah
This, Roguelazer, is the coolness of Perl in action. A completely useless script--but could bash do it??!?!!!? ...Actually, could it? I'm curious.
-rc
-rc
What does it do? I'm too lazy to check...