473,549 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C vs Perl

A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.( http://homepage.mac.com/billamend/images/patch.gif )

To see the comparison, go to ---> http://perl.hacker.freeservers.com/

Nov 13 '05 #1
17 4204
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.( http://homepage.mac.com/billamend/images/patch.gif )

To see the comparison, go to ---> http://perl.hacker.freeservers.com/


Where is the C++ version? I don't see it.
--
Noah Roberts
- "If you are not outraged, you are not paying attention."

Nov 13 '05 #2
Noah Roberts wrote:
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing
me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.(
http://homepage.mac.com/billamend/images/patch.gif )

To see the comparison, go to ---> http://perl.hacker.freeservers.com/

Where is the C++ version? I don't see it.


Don't know, but the original C code had an error. There was no new line, so it
would output the following;

I will not throw paper airplanes in class.I will not throw paper airplanes in
class.I will not....

Oh, here's a C++ version

#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
vector<string> v(500,string("I will not throw paper airplanes in class."));
copy(v.begin(), v.end(), ostream_iterato r(cout,"\n"));
return 0;
}

Nov 13 '05 #3
red floyd escribió:
Oh, here's a C++ version

#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
vector<string> v(500,string("I will not throw paper airplanes in class."));
copy(v.begin(), v.end(), ostream_iterato r(cout,"\n"));
return 0;
}


Mine is better ;)

#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;

int main ()
{
fill_n (ostream_iterat or <string> (cout, "\n"),
500, string ("I will not throw paper airplanes in
class") );
}

Regards.
Nov 13 '05 #4
len v <cc****@yahoo.c om> scribbled the following
on comp.lang.c:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.( http://homepage.mac.com/billamend/images/patch.gif ) To see the comparison, go to ---> http://perl.hacker.freeservers.com/


Yes, and I could implement a language called FoxTrot that would have the
following program:

Do it

translate into code that wrote "I will not throw paper airplanes in
class" 500 times into stdout. But I wouldn't guarantee FoxTrot would be
useful for anything else.

IOW, one-off cases like these are useless for comparing elegance of
languages.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
Nov 13 '05 #5
"red floyd" <no*****@here.d ude> wrote in message
news:Co******** *****@newssvr14 .news.prodigy.c om...
Oh, here's a C++ version

#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
vector<string> v(500,string("I will not throw paper airplanes in class.")); copy(v.begin(), v.end(), ostream_iterato r(cout,"\n"));
return 0;
}


Hmm, there's more includes than lines, what's the world coming to :-)

Nov 13 '05 #6
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking
causing me to edit the origional comic.


"Origional" ??

--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|
Nov 13 '05 #7
In article <3F************ ***@terra.es>, JU********@terr a.es says...

[ ... ]
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;

int main ()
{
fill_n (ostream_iterat or <string> (cout, "\n"),
500, string ("I will not throw paper airplanes in
class") );
}


std::string supports implicit conversions from C strings, so this can be
reduced a bit further:

#include <ostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;

int main ()
{
fill_n (ostream_iterat or <string> (cout, "\n"),
500, "I will not throw paper airplanes in class");
}

Also note that I've included <ostream> instead of <iostream> --
including <iostream> _usually_ declares std::cout, but isn't required
to.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Nov 13 '05 #8
Julián Albo <JU********@ter ra.es> wrote in message news:<3F******* ********@terra. es>...
red floyd escribi :
Oh, here's a C++ version

#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
vector<string> v(500,string("I will not throw paper airplanes in c

lass."));
copy(v.begin(), v.end(), ostream iterator(cout," \n"));
return 0;
}


Mine is better ;)

#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;

int main ()
{
fill n (ostream iterator <string> (cout, "\n"),
500, string ("I will not throw paper airplanes in
class") );
}


Feh.

#include <iostream>

struct C {
C() { std::cout << "I will not throw paper airplanes in class\n"; }
} c[500];

int main() { return 0; }

Why resort to complexity? Brevity is the soul of wit.

--
Stephen M. Webb
Nov 13 '05 #9
Jerry Coffin escribió:
int main ()
{
fill_n (ostream_iterat or <string> (cout, "\n"),
500, string ("I will not throw paper airplanes in
class") );
}
std::string supports implicit conversions from C strings, so this can be
reduced a bit further:


True. I was under the impression that implicit conversion will not allow
correct template argument deduction, but not.
Also note that I've included <ostream> instead of <iostream> --
including <iostream> _usually_ declares std::cout, but isn't required
to.


True again. My bad habit.

Regards.
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8124
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: ------------------------------------- test3.pl ------------------------------------- print "PERL Hello from Perl! (plain print)<br>\n"; print STDERR "PERL This is text sent to STDERR<br>\n";...
31
4730
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is great for pattern matching, text processing, and automated testing. Our company is really fixated on risk managnemt and the only way I can do enough...
0
9735
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile. I need it to be compiled with threads. Anyone have any wisdom on how best to do this? Here's a transcript of my latest attempt. It's long; you...
13
3235
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt fails in a rather dramatic way, spewing out thousands of "relocation remains"... I'm somewhat lost on what to do next, the documentation that came...
6
2986
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation for one of the Pear modules for creating XML and it didn't look like much. I've used Perl XML:Twig and I have the impression that there is more Perl...
4
3682
by: billb | last post by:
I installed a perl extension for PHP to use some perl inside my php primarily because I have perl working with oracle and not php and oracle. So I want to use my old perl scripts, and use the functionality of php. The extension uses the '$perl->eval' function. i am kind of stuck with the syntax or how to put the php variable into the perl...
21
34349
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready...
1
47378
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.