C vs Perl

Discussion in 'C Programming' started by len v, Oct 20, 2003.

  1. len v

    len v Guest

    len v, Oct 20, 2003
    #1
    1. Advertising

  2. len v

    Noah Roberts Guest

    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."
    Noah Roberts, Oct 20, 2003
    #2
    1. Advertising

  3. len v

    red floyd Guest

    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;
    }
    red floyd, Oct 20, 2003
    #3
  4. 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.
    =?iso-8859-1?Q?Juli=E1n?= Albo, Oct 20, 2003
    #4
  5. len v <> 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 () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "It sure is cool having money and chicks."
    - Beavis and Butt-head
    Joona I Palaste, Oct 20, 2003
    #5
  6. len v

    Serve La Guest

    "red floyd" <> wrote in message
    news:CoLkb.126$...
    > 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 :)
    Serve La, Oct 20, 2003
    #6
  7. len v wrote:

    > A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking
    > causing me to edit the origional comic.


    "Origional" ??

    --
    |_ CJSonnack <> _____________| How's my programming? |
    |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
    |_____________________________________________|_______________________|
    Programmer Dude, Oct 20, 2003
    #7
  8. len v

    len v Guest

    "red floyd" <> wrote in message
    news:CoLkb.126$...
    > 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;
    > }
    >



    The author of the comic received the same ridicule regarding the
    error.... --> http://homepage.mac.com/billamend/ Half way down you will
    find his patch.


    umm.... I don't think I can fit the c++ version on the chalk board.
    len v, Oct 20, 2003
    #8
  9. len v

    red floyd Guest

    len v wrote:
    > [redacted]
    > umm.... I don't think I can fit the c++ version on the chalk board.


    What about Julian Albo's (sorry Julian, don't know how to put the accent on in Moz...)?

    His is three lines shorter:
    doesn't need #include <vector>
    uses the implicit return 0 from main
    doesn't need to declare the vector I used

    Would that fit? :)
    red floyd, Oct 21, 2003
    #9
  10. len v

    Joe Wright Guest

    Programmer Dude wrote:
    >
    > len v wrote:
    >
    > > A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking
    > > causing me to edit the origional comic.

    >
    > "Origional" ??
    >
    > --
    > |_ CJSonnack <> _____________| How's my programming? |
    > |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
    > |_____________________________________________|_______________________|

    I just hate spilling errors.
    --
    Joe Wright http://www.jw-wright.com
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
    Joe Wright, Oct 21, 2003
    #10
  11. len v

    len v Guest

    "Joe Wright" <> wrote in message
    news:...
    > Programmer Dude wrote:
    > >
    > > len v wrote:
    > >
    > > > A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking
    > > > causing me to edit the origional comic.

    > >
    > > "Origional" ??
    > >
    > > --
    > > |_ CJSonnack <> _____________| How's my programming? |
    > > |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
    > > |_____________________________________________|_______________________|

    > I just hate spilling errors.
    > --
    > Joe Wright http://www.jw-wright.com
    > "Everything should be made as simple as possible, but not simpler."
    > --- Albert Einstein ---



    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.
    len v, Oct 21, 2003
    #11
  12. len v

    len v Guest

    "red floyd" <> wrote in message
    news:tOZkb.3605$...
    > len v wrote:
    > > [redacted]
    > > umm.... I don't think I can fit the c++ version on the chalk board.

    >
    > What about Julian Albo's (sorry Julian, don't know how to put the accent

    on in Moz...)?
    >
    > His is three lines shorter:
    > doesn't need #include <vector>
    > uses the implicit return 0 from main
    > doesn't need to declare the vector I used
    >
    > Would that fit? :)
    >


    That just might do it. I'll try and repost the link.

    I wonder if I could fit COBOL, Fortran or Java code in there too. Ouch. My
    brain just started to hurt. It's been awhile.
    len v, Oct 21, 2003
    #12
  13. len v

    len v Guest

    "Joona I Palaste" <> wrote in message
    news:bn164i$qho$...
    > len v <> 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.(

    ttp://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 () ------------- Finland --------\
    > \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    > "It sure is cool having money and chicks."
    > - Beavis and Butt-head



    I see your point and that is exactly what Perl is all about. If your
    FoxTrot implementation had something to offer the community then FoxTrot
    would be added to Perl.

    Perhaps you could help me out? I've been trying to remember my C and C++
    code, it's been about 5 years. How do I swap the values of 2 strings?
    len v, Oct 21, 2003
    #13
  14. len v

    Jirka Klaue Guest

    len v wrote:
    ....
    > Perhaps you could help me out? I've been trying to remember my C and C++
    > code, it's been about 5 years. How do I swap the values of 2 strings?


    Could you define "value of string", please?

    Jirka
    Jirka Klaue, Oct 21, 2003
    #14
  15. len v

    len v Guest

    "Jirka Klaue" <-berlin.de> wrote in message
    news:bn229k$bov$-Berlin.DE...
    > len v wrote:
    > ...
    > > Perhaps you could help me out? I've been trying to remember my C and C++
    > > code, it's been about 5 years. How do I swap the values of 2 strings?

    >
    > Could you define "value of string", please?
    >
    > Jirka
    >


    Sure --
    I was using a string (scalar) as an example, it could be any two basic types
    (ex: int's, char's, float's, reference's, arrays etc.) However, in keeping
    with the original question:

    CString m_firstName;
    CString m_lastName;

    put the value of (contents of, address of) m_firstName in m_lastName and put
    m_lastName in m_firstName.

    Regards
    Len
    len v, Oct 21, 2003
    #15
  16. len v

    Jirka Klaue Guest

    len v wrote:

    >>Could you define "value of string", please?

    ....
    > Sure --

    ....
    > CString m_firstName;
    > CString m_lastName;


    There is no CString in C, C++ or Perl.

    To clarify my question:

    char a[] = "C", b[] = "C++";

    char *a = "C", *b = "C++";

    Are a and b strings? What are their values?
    How would *you* swap their "values"?

    Jirka
    Jirka Klaue, Oct 21, 2003
    #16
  17. len v

    len v Guest

    "Jirka Klaue" <-berlin.de> wrote in message
    news:bn24i2$djm$-Berlin.DE...
    > len v wrote:
    >
    > >>Could you define "value of string", please?

    > ...
    > > Sure --

    > ...
    > > CString m_firstName;
    > > CString m_lastName;

    >
    > There is no CString in C, C++ or Perl.
    >
    > To clarify my question:
    >
    > char a[] = "C", b[] = "C++";
    >
    > char *a = "C", *b = "C++";
    >
    > Are a and b strings? What are their values?
    > How would *you* swap their "values"?
    >
    > Jirka
    >


    Perhaps I'm not reading it correctly:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;111923

    A string would be a scalar. In Perl it would be $a and $b
    http://www.perl.com/pub/a/2000/11/begperl2.html No need to declare the
    type. Scalars can be a numbers, text, references to a scalar, references to
    an array, or references to a hash, or references to a sub (a function or
    method). And no need to pre-declare the variable prior to its' use.

    Example of strings (scalars) in Perl:

    $a = 'C';
    $b = 'C++';

    $tmp = $a;
    $a = $b;
    $b = $tmp;

    However this is too much work for me, so I was thinking more like:
    $a = 'C';
    $b = 'C++';

    ($a, $b) = ($b, $a);

    or

    ($a, $b) = ('C', 'C++');
    ($a, $b) = ($b, $a);


    Regards
    Len
    len v, Oct 21, 2003
    #17
  18. len v

    Jirka Klaue Guest

    len v wrote:

    >>There is no CString in C, C++ or Perl.

    ....
    > Perhaps I'm not reading it correctly:
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;111923


    CString is part of MFC which is *not* part of C++.
    Ever heard of std::string?

    > Example of strings (scalars) in Perl:
    >
    > $a = 'C';
    > $b = 'C++';
    >
    > $tmp = $a;
    > $a = $b;
    > $b = $tmp;
    >
    > However this is too much work for me, so I was thinking more like:
    > $a = 'C';
    > $b = 'C++';
    >
    > ($a, $b) = ($b, $a);
    >
    > or
    >
    > ($a, $b) = ('C', 'C++');
    > ($a, $b) = ($b, $a);


    std::swap(a, b);

    Jirka
    Jirka Klaue, Oct 21, 2003
    #18
  19. len v

    len v Guest

    "Jirka Klaue" <-berlin.de> wrote in message
    news:bn276m$f2c$-Berlin.DE...
    > len v wrote:
    >
    > >>There is no CString in C, C++ or Perl.

    > ...
    > > Perhaps I'm not reading it correctly:
    > > http://support.microsoft.com/default.aspx?scid=kb;en-us;111923

    >
    > CString is part of MFC which is *not* part of C++.
    > Ever heard of std::string?
    >
    > > Example of strings (scalars) in Perl:
    > >
    > > $a = 'C';
    > > $b = 'C++';
    > >
    > > $tmp = $a;
    > > $a = $b;
    > > $b = $tmp;
    > >
    > > However this is too much work for me, so I was thinking more like:
    > > $a = 'C';
    > > $b = 'C++';
    > >
    > > ($a, $b) = ($b, $a);
    > >
    > > or
    > >
    > > ($a, $b) = ('C', 'C++');
    > > ($a, $b) = ($b, $a);

    >
    > std::swap(a, b);
    >
    > Jirka
    >



    That is what I'm looking for. Thank you
    len v, Oct 21, 2003
    #19
  20. len v

    Noah Roberts Guest

    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.


    --
    Noah Roberts
    - "If you are not outraged, you are not paying attention."
    Noah Roberts, Oct 21, 2003
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,784
  2. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    294
    PerlFAQ Server
    Jan 23, 2011
  3. PerlFAQ Server
    Replies:
    0
    Views:
    673
    PerlFAQ Server
    Feb 3, 2011
  4. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    289
    PerlFAQ Server
    Feb 27, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    676
    PerlFAQ Server
    Apr 4, 2011
Loading...

Share This Page