473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 4191
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.