473,484 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Create 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 4198
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_iterator(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_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") );
}

Regards.
Nov 13 '05 #4
len v <cc****@yahoo.com> 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.helsinki.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.dude> wrote in message
news:Co*************@newssvr14.news.prodigy.com...
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_iterator(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********@terra.es says...

[ ... ]
#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") );
}


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_iterator <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********@terra.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_iterator <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
"Stephen M. Webb" escribió:
#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.


Nice solution, but vastes memory if great values of 500 were used ;)

Regards.
Nov 13 '05 #11

"Stephen M. Webb" <st**********@bregmasoft.com> wrote in message
news:34**************************@posting.google.c om...
Julián Albo <JU********@terra.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.


Well then, throw out that 'return' statement too.
-Mike

Nov 13 '05 #12
len v wrote:
...causing me to edit the origional comic.

"Origional" ??

Looks like I spelled it wrong on the web site too.


That was why I mentioned it. (-:
I've always maintained that a programmer does not have to spell
correctly, just consistent, either right or wrong - the syntax
checker does not care.


I would disagree. For many reasons.

Comments, tech docs, communicating effectively with others.....

--
|_ CJSonnack <Ch***@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|
Nov 13 '05 #13
W K

"Programmer Dude" <Ch***@Sonnack.com> wrote in message
news:3F***************@Sonnack.com...
len v wrote:
> ...causing me to edit the origional comic.

"Origional" ??


Looks like I spelled it wrong on the web site too.


That was why I mentioned it. (-:
I've always maintained that a programmer does not have to spell
correctly, just consistent, either right or wrong - the syntax
checker does not care.


I would disagree. For many reasons.

Comments, tech docs, communicating effectively with others.....


They're all dyslexic too, so it doesn't matter.
Nov 13 '05 #14
Jerry Coffin wrote:

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


The C++ standard appears to require std::cout be declared in <iostream>:

27.3 Standard iostream objects [lib.iostream.objects]

Header <iostream> synopsis

namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;

extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
}

As far as I know, the thing that people usually assume is in iostream
which is technically not required to be is std::endl - though I believe
this is considered a defect.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 13 '05 #15
In article <Xv*************@newsread4.news.pas.earthlink.net> ,
us*********************@neverbox.com says...

[ ... ]
The C++ standard appears to require std::cout be declared in <iostream>:


Oops -- you're absolutely right. My apologies for the incorrect post.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Nov 13 '05 #16
Jerry Coffin <jc*****@taeus.com> writes:
Also note that I've included <ostream> instead of <iostream> --
including <iostream> _usually_ declares std::cout, but isn't required
to.


This is a bizarre statement. Perhaps you meant the other way
around, but that doesn't make much sense either. Read your
standard, and try again.

#include <iostream>

Is *guaranteed* to declare as follows:

namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;
extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
}

It has not been my experience that ostream "usually" declares
std::cout at all; and it certainly isn't required to.

I'd have fixed the cross-post, except that I didn't want people
who are only reading alt.comp.lang.c and comp.lang.c to come away
with the wrong idea, either. Followups have been fixed.

--
Micah Cowan
mi***@cowan.name
Nov 13 '05 #17
Noah Roberts <nr******@dontemailme.com> writes:
len v wrote:
Note to self. Find spell checker for vi.
Looks like I spelled it wrong on the web site too. I've always
maintained
that a programmer does not have to spell correctly, just consistent, either
right or wrong - the syntax checker does not care.


My compiler really doesn't like it when I spell freind wrong.


Mine doesn't care.

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #18

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

Similar topics

4
8118
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: -------------------------------------...
31
4719
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...
0
9731
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....
13
3220
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...
6
2979
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...
4
3668
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...
21
34316
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...
1
47341
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...
0
6950
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...
0
7140
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6811
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...
0
7209
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...
1
4841
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3044
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...
0
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1355
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 ...
1
588
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.