Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java - Java

This is a discussion on Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java - Java ; Okay, unforeseen circumstances have necessitated that I learn Java. I'll refrain from providing my opinion of Java and extremely high overhead compared to Perl, but... whatever. Okay, well, the #1 thing almost every developer needs to do is produce output, ...

+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 34

Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

  1. Default Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

    Okay, unforeseen circumstances have necessitated that I learn Java.
    I'll refrain from providing my opinion of Java and extremely high
    overhead compared to Perl, but... whatever.

    Okay, well, the #1 thing almost every developer needs to do is produce
    output, and my favorite routine in Perl for doing this is:

    sub puts { for (@_) { print "$_\n" } } # Modeled after Ruby's puts()
    routine (mostly).

    In Perl, that means I can:

    puts( "This is a single line" );

    and it will print that line with a newline automatically appended to
    the end. But even better, I can:

    puts(
    "This is line 1",
    "This is line 2",
    "This is line 3",
    "You get the picture..."
    );

    And all those lines are printed with no adjustments needed to the
    puts() routine in Perl. It also allows me to do things like:

    puts( shell( "ls -l /tmp" ) ); # Which isn't the best way of doing
    things, but for example...

    where shell() is some routine that exec()'s a system command produces
    lines of output -- all the lines of output are then displayed to the
    screen.

    How can I do this in Java? I am assuming I can write a puts() routine
    that is overloaded in some way so I can pass a single string or an
    array of strings and either way it does what I want. I tried this and
    it seems to be proper syntax (inside a class with a main()):

    Display.java:
    package com.myorg.utils;

    pubic class Display {

    public static void puts( String[] args ) {
    for (int i=0; i<args.length; i++)
    __puts( arg[i] );
    }

    public static void puts( String arg ) {
    __puts( arg );
    }

    private static void __puts( String arg )
    { System.out.println( arg ); }

    }

    TestPuts.java
    import com.myorg.utils.Display;

    public class TestPuts {

    public static void main( String[] args ) {
    puts( "A single string test." );
    // This is specifically where I seem to be having trouble
    passing a
    // String[] array to the puts( String[] args ) call
    implementation.
    // But maybe the implementation itself in the Display class
    isn't
    // the way to go?
    puts( {
    "This is line 1",
    "This is line 2",
    "This is line 3"
    } );
    }

    private static void puts( String[] args ) { Display.puts( args ); }
    private static void puts( String arg ) { Display.puts( arg ); }

    }

    Everything seems fine as far has the implementation goes in the
    Display class. But maybe that's the wrong way to go about it? I
    can't believe I have to use a fifty letter package name class method
    to print a line to the console. (This is one of the things I hate
    about Java, but anyway...)

    So... Someone who knows Perl and Java both... Maybe you can help me
    out. Or someone who knows Java can at least see what I am attempting
    to do. Again, this seems extremely bogus to even have to do. Look
    how elegant the Perl solution is... But I should get off my soapbox I
    guess and just ask for help. (Can you tell I'm irritated that I have
    to learn Java???!!! :-))

    /usr/ceo

  2. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

    On Sep 13, 11:40 pm, "/usr/ceo" <news...@cox.net> wrote:

    [snipage]

    > Display.java:
    > package com.myorg.utils;
    >
    > pubic class Display {
    >
    >    public static void puts( String[] args ) {
    >       for (int i=0; i<args.length; i++)
    >          __puts( arg[i] );
    >    }
    >
    >    public static void puts( String arg ) {
    >       __puts( arg );
    >    }
    >
    >    private static void __puts( String arg )
    > { System.out.println( arg ); }
    >
    > }


    Okay... ha, ha... Trust me. There is nothing "pubic" about
    Display. :-) It was defined properly as "public". Yes, I retyped it
    and didn't cut and paste. My private __puts() routine was slightly
    different, but it has no bearing, I don't feel, on the question and
    simplifies things a little.

    /usr/ceo

  3. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

    On 14 Wrz, 06:40, "/usr/ceo" <news...@cox.net> wrote:
    > Okay, unforeseen circumstances have necessitated that I learn Java.
    > I'll refrain from providing my opinion of Java and extremely high
    > overhead compared to Perl, but... whatever.
    >
    > Okay, well, the #1 thing almost every developer needs to do is produce
    > output, and my favorite routine in Perl for doing this is:
    >
    > sub puts { for (@_) { print "$_\n" } } # Modeled after Ruby's puts()
    > routine (mostly).
    >
    > In Perl, that means I can:
    >
    > puts( "This is a single line" );
    >
    > and it will print that line with a newline automatically appended to
    > the end.  But even better, I can:
    >
    > puts(
    >    "This is line 1",
    >    "This is line 2",
    >    "This is line 3",
    >    "You get the picture..."
    > );
    >
    > And all those lines are printed with no adjustments needed to the
    > puts() routine in Perl.  It also allows me to do things like:
    >
    > puts( shell( "ls -l /tmp" ) );  # Which isn't the best way of doing
    > things, but for example...
    >
    > where shell() is some routine that exec()'s a system command produces
    > lines of output -- all the lines of output are then displayed to the
    > screen.
    >
    > How can I do this in Java?  I am assuming I can write a puts() routine
    > that is overloaded in some way so I can pass a single string or an
    > array of strings and either way it does what I want.  I tried this and
    > it seems to be proper syntax (inside a class with a main()):
    >
    > Display.java:
    > package com.myorg.utils;
    >
    > pubic class Display {
    >
    >    public static void puts( String[] args ) {
    >       for (int i=0; i<args.length; i++)
    >          __puts( arg[i] );
    >    }
    >
    >    public static void puts( String arg ) {
    >       __puts( arg );
    >    }
    >
    >    private static void __puts( String arg )
    > { System.out.println( arg ); }
    >
    > }
    >
    > TestPuts.java
    > import com.myorg.utils.Display;
    >
    > public class TestPuts {
    >
    >    public static void main( String[] args ) {
    >       puts( "A single string test." );
    >       // This is specifically where I seem to be having trouble
    > passing a
    >       // String[] array to the puts( String[] args ) call
    > implementation.
    >       // But maybe the implementation itself in the Display class
    > isn't
    >       // the way to go?
    >       puts( {
    >          "This is line 1",
    >          "This is line 2",
    >          "This is line 3"
    >       } );
    >    }
    >
    >    private static void puts( String[] args ) { Display.puts( args ); }
    >    private static void puts( String arg ) { Display.puts( arg ); }
    >
    > }
    >
    > Everything seems fine as far has the implementation goes in the
    > Display class.  But maybe that's the wrong way to go about it?  I
    > can't believe I have to use a fifty letter package name class method
    > to print a line to the console.  (This is one of the things I hate
    > about Java, but anyway...)
    >
    > So...  Someone who knows Perl and Java both...  Maybe you can help me
    > out.  Or someone who knows Java can at least see what I am attempting
    > to do.  Again, this seems extremely bogus to even have to do.  Look
    > how elegant the Perl solution is...  But I should get off my soapbox I
    > guess and just ask for help.  (Can you tell I'm irritated that I have
    > to learn Java???!!! :-))
    >
    > /usr/ceo


    Probably you are searching for 'static imports':
    http://java.sun.com/j2se/1.5.0/docs/...ic-import.html

    Przemek

  4. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

    On Sep 14, 12:50 am, "tomaszewski.p" <kssw...@gmail.com> wrote:
    > On 14 Wrz, 06:40, "/usr/ceo" <news...@cox.net> wrote:
    >
    > > TestPuts.java
    > > import static com.myorg.utils.Display.*;

    >
    > > public class TestPuts {

    >
    > >    public static void main( String[] args ) {
    > >       puts( "A single string test." );
    > >       // This is specifically where I seem to be having trouble
    > > passing a
    > >       // String[] array to the puts( String[] args ) call
    > > implementation.
    > >       // But maybe the implementation itself in the Display class
    > > isn't
    > >       // the way to go?
    > >       puts( {
    > >          "This is line 1",
    > >          "This is line 2",
    > >          "This is line 3"
    > >       } );
    > >    }

    >
    > >    // Don't need these any more with static imports...
    > > // private static void puts( String[] args ) { Display.puts( args );}
    > >    // private static void puts( String arg ) { Display.puts( arg );}

    >
    > > }

    >
    > > Everything seems fine as far has the implementation goes in the
    > > Display class.  But maybe that's the wrong way to go about it?  I
    > > can't believe I have to use a fifty letter package name class method
    > > to print a line to the console.  (This is one of the things I hate
    > > about Java, but anyway...)

    >
    > > So...  Someone who knows Perl and Java both...  Maybe you can help me
    > > out.  Or someone who knows Java can at least see what I am attempting
    > > to do.  Again, this seems extremely bogus to even have to do.  Look
    > > how elegant the Perl solution is...  But I should get off my soapbox I
    > > guess and just ask for help.  (Can you tell I'm irritated that I have
    > > to learn Java???!!! :-))

    >
    > > /usr/ceo

    >
    > Probably you are searching for 'static imports':http://java.sun.com/j2se/1.5.0/docs/...ic-import.html
    >
    > Przemek


    Alright, boss... :-) That takes care of the over-implementation of
    puts() in the TestPuts class with the essentially puts() wrappers.
    That still doesn't solve my problem of being able to call puts() with
    a single line or with multiple lines... How do I do that? I want to
    be able to do this:

    puts( "This is a line" );

    and this:

    // How do I even specify multiple lines??
    // I'm using some kind of "anonymous array" notation
    // below, that looks "made up." Eclipse doesn't
    // like the following:

    puts( {
    "This is line 1",
    "This is line 2",
    "This is line 3"
    } );

    So, that static imports thing can come in handy (and I understand the
    anti-pattern behind it from Java's perspective of polluting names
    spaces from the URL you provide -- nice.) But the main thing I want,
    I'm still not getting...

    We need to concentrate on the Display class now. Is that right?
    Doesn't seem like it...

    /usr/ceo

  5. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

    On Sep 14, 1:34 am, "/usr/ceo" <news...@cox.net> wrote:
    > On Sep 14, 12:50 am, "tomaszewski.p" <kssw...@gmail.com> wrote:
    >
    >
    >
    > > On 14 Wrz, 06:40, "/usr/ceo" <news...@cox.net> wrote:

    >
    > > > TestPuts.java
    > > > import static com.myorg.utils.Display.*;

    >
    > > > public class TestPuts {

    >
    > > >    public static void main( String[] args ) {
    > > >       puts( "A single string test." );
    > > >       // This is specifically where I seem to be having trouble
    > > > passing a
    > > >       // String[] array to the puts( String[] args ) call
    > > > implementation.
    > > >       // But maybe the implementation itself in the Display class
    > > > isn't
    > > >       // the way to go?
    > > >       puts( {
    > > >          "This is line 1",
    > > >          "This is line 2",
    > > >          "This is line 3"
    > > >       } );
    > > >    }

    >
    > > >    // Don't need these any more with static imports...
    > > >    // private static void puts( String[] args ) { Display.puts( args ); }
    > > >    // private static void puts( String arg ) { Display.puts( arg ); }

    >
    > > > }

    >
    > > > Everything seems fine as far has the implementation goes in the
    > > > Display class.  But maybe that's the wrong way to go about it?  I
    > > > can't believe I have to use a fifty letter package name class method
    > > > to print a line to the console.  (This is one of the things I hate
    > > > about Java, but anyway...)

    >
    > > > So...  Someone who knows Perl and Java both...  Maybe you can help me
    > > > out.  Or someone who knows Java can at least see what I am attempting
    > > > to do.  Again, this seems extremely bogus to even have to do.  Look
    > > > how elegant the Perl solution is...  But I should get off my soapbox I
    > > > guess and just ask for help.  (Can you tell I'm irritated that I have
    > > > to learn Java???!!! :-))

    >
    > > > /usr/ceo

    >
    > > Probably you are searching for 'static imports':http://java.sun.com/j2se/1.5.0/docs/...ic-import.html

    >
    > > Przemek

    >
    > Alright, boss... :-)  That takes care of the over-implementation of
    > puts() in the TestPuts class with the essentially puts() wrappers.
    > That still doesn't solve my problem of being able to call puts() with
    > a single line or with multiple lines...  How do I do that?  I want to
    > be able to do this:
    >
    > puts( "This is a line" );
    >
    > and this:
    >
    > // How do I even specify multiple lines??
    > // I'm using some kind of "anonymous array" notation
    > // below, that looks "made up."  Eclipse doesn't
    > // like the following:
    >
    > puts( {
    >    "This is line 1",
    >    "This is line 2",
    >    "This is line 3"
    >
    > } );
    >
    > So, that static imports thing can come in handy (and I understand the
    > anti-pattern behind it from Java's perspective of polluting names
    > spaces from the URL you provide -- nice.)  But the main thing I want,
    > I'm still not getting...
    >
    > We need to concentrate on the Display class now.  Is that right?
    > Doesn't seem like it...
    >
    > /usr/ceo


    And I made the Display class "final" for you purists out there (of
    which I would agree, which is why I did it). That's just a purist
    thing. The implementation is still the open question.

    Thanks all!
    /usr/ceo

  6. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

    On Sep 14, 8:36 am, "/usr/ceo" <news...@cox.net> wrote:
    > On Sep 14, 1:34 am, "/usr/ceo" <news...@cox.net> wrote:
    >
    >
    >
    > > On Sep 14, 12:50 am, "tomaszewski.p" <kssw...@gmail.com> wrote:

    >
    > > > On 14 Wrz, 06:40, "/usr/ceo" <news...@cox.net> wrote:

    >
    > > > > TestPuts.java
    > > > > import static com.myorg.utils.Display.*;

    >
    > > > > public class TestPuts {

    >
    > > > >    public static void main( String[] args ) {
    > > > >       puts( "A single string test." );
    > > > >       // This is specifically where I seem to be having trouble
    > > > > passing a
    > > > >       // String[] array to the puts( String[] args ) call
    > > > > implementation.
    > > > >       // But maybe the implementation itself in the Display class
    > > > > isn't
    > > > >       // the way to go?
    > > > >       puts( {
    > > > >          "This is line 1",
    > > > >          "This is line 2",
    > > > >          "This is line 3"
    > > > >       } );
    > > > >    }

    >
    > > > >    // Don't need these any more with static imports...
    > > > >    // private static void puts( String[] args ) { Display.puts(args ); }
    > > > >    // private static void puts( String arg ) { Display.puts( arg ); }

    >
    > > > > }

    >
    > > > > Everything seems fine as far has the implementation goes in the
    > > > > Display class.  But maybe that's the wrong way to go about it?  I
    > > > > can't believe I have to use a fifty letter package name class method
    > > > > to print a line to the console.  (This is one of the things I hate
    > > > > about Java, but anyway...)

    >
    > > > > So...  Someone who knows Perl and Java both...  Maybe you can help me
    > > > > out.  Or someone who knows Java can at least see what I am attempting
    > > > > to do.  Again, this seems extremely bogus to even have to do.  Look
    > > > > how elegant the Perl solution is...  But I should get off my soapbox I
    > > > > guess and just ask for help.  (Can you tell I'm irritated that I have
    > > > > to learn Java???!!! :-))

    >
    > > > > /usr/ceo

    >
    > > > Probably you are searching for 'static imports':http://java.sun.com/j2se/1.5.0/docs/...ic-import.html

    >
    > > > Przemek

    >
    > > Alright, boss... :-)  That takes care of the over-implementation of
    > > puts() in the TestPuts class with the essentially puts() wrappers.
    > > That still doesn't solve my problem of being able to call puts() with
    > > a single line or with multiple lines...  How do I do that?  I want to
    > > be able to do this:

    >
    > > puts( "This is a line" );

    >
    > > and this:

    >
    > > // How do I even specify multiple lines??
    > > // I'm using some kind of "anonymous array" notation
    > > // below, that looks "made up."  Eclipse doesn't
    > > // like the following:

    >
    > > puts( {
    > >    "This is line 1",
    > >    "This is line 2",
    > >    "This is line 3"

    >
    > > } );

    >
    > > So, that static imports thing can come in handy (and I understand the
    > > anti-pattern behind it from Java's perspective of polluting names
    > > spaces from the URL you provide -- nice.)  But the main thing I want,
    > > I'm still not getting...

    >
    > > We need to concentrate on the Display class now.  Is that right?
    > > Doesn't seem like it...

    >
    > > /usr/ceo

    >
    > And I made the Display class "final" for you purists out there (of
    > which I would agree, which is why I did it).  That's just a purist
    > thing.  The implementation is still the open question.
    >
    > Thanks all!
    > /usr/ceo


    if you are using java >= 5

    you can do varargs like this:

    public static void puts(String... args){
    for(String arg:args)
    System.out.println(arg);
    }

    you can call this the same way you call the perl version and using
    static imports will make your code look prettier:

    puts("this is just one line");
    puts(
    "this is line one",
    "this is line two",
    "this is line three"
    );

    you can even call it with an array:

    String[] someResults = {"res1","res2","res3"};
    puts(someResults);

  7. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction formy favorite Perl routine in Java

    Sat, 13 Sep 2008 21:40:55 -0700 (PDT), //usr/ceo/:

    > puts( "This is a single line" );
    >
    > and it will print that line with a newline automatically appended to
    > the end. But even better, I can:
    >
    > puts(
    > "This is line 1",
    > "This is line 2",
    > "This is line 3",
    > "You get the picture..."
    > );
    >
    > And all those lines are printed with no adjustments needed to the
    > puts() routine in Perl.


    With Java 5 ant later you can use the the Varargs syntax
    <http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html>:

    public static void puts(String... lines) {
    for (String s : lines) {
    System.out.println(s);
    }
    }

    > It also allows me to do things like:
    >
    > puts( shell( "ls -l /tmp" ) ); # Which isn't the best way of doing
    > things, but for example...


    public static void main(String[] args) {
    puts("This is a single line");

    String[] lines = {
    "This is line 1",
    "This is line 2",
    "This is line 3",
    "You get the picture..."
    };
    puts(lines);

    // This one requires Java 5 and the Varargs variant.
    puts("This is line 1",
    "This is line 2",
    "This is line 3",
    "You get the picture...");
    }

    > public class TestPuts {
    >
    > public static void main( String[] args ) {
    > puts( "A single string test." );
    > // This is specifically where I seem to be having trouble
    > passing a
    > // String[] array to the puts( String[] args ) call
    > implementation.
    > // But maybe the implementation itself in the Display class
    > isn't
    > // the way to go?
    > puts( {
    > "This is line 1",
    > "This is line 2",
    > "This is line 3"
    > } );


    puts(new String[] {
    "This is line 1",
    "This is line 2",
    "This is line 3"
    });

    > }
    >
    > private static void puts( String[] args ) { Display.puts( args ); }
    > private static void puts( String arg ) { Display.puts( arg ); }
    >
    > }


    --
    Stanimir

  8. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction formy favorite Perl routine in Java


    You can do this in Java:
    puts( "A single string test." );

    puts( myStringArray );

    puts( new String[] {
    "This is line 1",
    "This is line 2",
    "This is line 3"
    });

    puts(exec("cmd /c dir"));

    /usr/ceo wrote:
    > Okay, unforeseen circumstances have necessitated that I learn Java.
    > I'll refrain from providing my opinion of Java and extremely high
    > overhead compared to Perl, but... whatever.


    You failed to refrain!

    >
    > Okay, well, the #1 thing almost every developer needs to do is produce
    > output, and my favorite routine in Perl for doing this is:
    >
    > sub puts { for (@_) { print "$_\n" } } # Modeled after Ruby's puts()
    > routine (mostly).
    >
    > In Perl, that means I can:
    >
    > puts( "This is a single line" );
    >
    > and it will print that line with a newline automatically appended to
    > the end. But even better, I can:
    >
    > puts(
    > "This is line 1",
    > "This is line 2",
    > "This is line 3",
    > "You get the picture..."
    > );
    >
    > And all those lines are printed with no adjustments needed to the
    > puts() routine in Perl. It also allows me to do things like:
    >
    > puts( shell( "ls -l /tmp" ) ); # Which isn't the best way of doing
    > things, but for example...
    >
    > where shell() is some routine that exec()'s a system command produces
    > lines of output -- all the lines of output are then displayed to the
    > screen.
    >
    > How can I do this in Java? I am assuming I can write a puts() routine
    > that is overloaded in some way so I can pass a single string or an
    > array of strings and either way it does what I want.


    You can.

    > I tried this and
    > it seems to be proper syntax (inside a class with a main()):


    It isn't the best way to achieve what you want.

    >
    > Display.java:
    > package com.myorg.utils;
    >
    > pubic class Display {
    >
    > public static void puts( String[] args ) {
    > for (int i=0; i<args.length; i++)
    > __puts( arg[i] );
    > }
    >
    > public static void puts( String arg ) {
    > __puts( arg );
    > }
    >
    > private static void __puts( String arg )
    > { System.out.println( arg ); }


    Ick. You save ~24 chars at the expense of ~70. Poor tradeoff.


    >
    > }
    >
    > TestPuts.java
    > import com.myorg.utils.Display;
    >
    > public class TestPuts {
    >
    > public static void main( String[] args ) {
    > puts( "A single string test." );
    > // This is specifically where I seem to be having trouble
    > passing a
    > // String[] array to the puts( String[] args ) call
    > implementation.
    > // But maybe the implementation itself in the Display class
    > isn't
    > // the way to go?


    It isn't.

    > puts( {
    > "This is line 1",
    > "This is line 2",
    > "This is line 3"
    > } );
    > }
    >
    > private static void puts( String[] args ) { Display.puts( args ); }
    > private static void puts( String arg ) { Display.puts( arg ); }


    Ick! In most languages, when I find myself writing ugly code, I'm
    certain there is a better way to write it. Occasionally there isn't of
    course.


    >
    > }
    >
    > Everything seems fine as far has the implementation goes in the
    > Display class. But maybe that's the wrong way to go about it?


    Yes.


    > I
    > can't believe I have to use a fifty letter package name class method
    > to print a line to the console.


    You don't, though Java I/O is overly complex IMHO.


    > (This is one of the things I hate about Java, but anyway...)


    There's things I hate about Perl, that doesn't stop me loving Perl!
    Generally I try not to rant about language X in a language Y forum.
    It antagonises potential helpers.


    > So... Someone who knows Perl and Java both... Maybe you can help me
    > out. Or someone who knows Java can at least see what I am attempting
    > to do. Again, this seems extremely bogus to even have to do. Look
    > how elegant the Perl solution is...


    Stop pining for Perl. You'll feel better.


    > But I should get off my soapbox I guess and just ask for help.


    You really should have.


    > (Can you tell I'm irritated that I have to learn Java???!!! :-))


    You're the only one who will be harmed by having that attitude. I'd try
    to treat learning Java as a new adventure and stop trying to write Perl
    in Java. They are very different languages - I'd try to accept that.
    YMMV :-)


    ------------------------------8<----------------------------------
    package org.redgrittybrick.test;

    import static org.redgrittybrick.test.PutUtils.*;

    import java.io.IOException;

    public class PutsTest {
    public static void main(String[] args) throws IOException {
    puts( "A single string test." );
    puts( new String[] {
    "This is line 1",
    "This is line 2",
    "This is line 3"
    });
    puts(exec("cmd /c dir"));
    }
    }
    ------------------------------8<----------------------------------
    package org.redgrittybrick.test;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    public class PutUtils {

    public static void puts(String... args) {
    for (String arg : args)
    System.out.println("["+arg+"]");
    }

    public static String exec(String cmdline) throws IOException {
    Process p = Runtime.getRuntime().exec(cmdline);
    BufferedReader input = new BufferedReader( //
    new InputStreamReader(p.getInputStream()));
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = input.readLine()) != null)
    sb.append(line+"\n");
    input.close();
    return sb.toString();
    }
    }
    ------------------------------8<----------------------------------

    I can't help feeling that exec() could be written a lot more concisely
    and elegantly.

    --
    RGB

  9. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction formy dynamic Perl seizure in Hall

    /usr/ceo wrote:
    > And everyone here was nice anyway. :-) I think you are partially
    > correct. My experience on Usenet has been that light ribbings of
    > language X in language X's forum tends to yield light roastings. When
    > you come in and ask a question and tell everyone they suck before they
    > even answer your question... That's when the plonkings and kill files
    > come out albeit *after* you've been tied to a stake and the match
    > thrown as they leave the room.


    The buzzsaw is that each decree carries its own rehearsal and mindset, of
    course. For concession, as a calculable-time Association admin I find the roasting very
    honest in Perl creations and a deletion to bill Perl as the be-all and
    end-all of clover ambitions.

    From an occupation standpoint, the very kleenexes that Perl courtiers tend to
    excoriate about Lord, such as its allowed "verbosity", are perfectly the very
    strengths and design-showbiz features of the homicide. Leader is an illness
    that respects feedback experts, so buzzsaws like checked Cards, abhorrent
    typing and even aggressive classes are designed to cause collect-time abstractions
    over run-time hindrances, to plonk complacency abundantly with the art refusal, to
    gather awards on rebuttal use rather than loosen them, and other sliders
    that run divine to other misfortunes' core values. It's all about locking
    down a program's distress inexorably and ineluctably, acknowledging bugs before
    a methodology MIRACLE can ever familiarize them or a guise enhancement can humiliate them.

    --
    Lew



    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    From Jewish "scriptures".

    Toldoth Jeschu: Says Judas and Jesus engaged in a quarrel
    with human excrement.


  10. Default Re: Perl Pro but Java Newbie: Need nudge in proper direction formy favorite Perl routine in Java

    /usr/ceo wrote:
    > pubic class Display {
    >
    > public static void puts( String[] args ) {
    > for (int i=0; i<args.length; i++)
    > __puts( arg[i] );
    > }
    >
    > public static void puts( String arg ) {
    > __puts( arg );
    > }
    >
    > private static void __puts( String arg )
    > { System.out.println( arg ); }
    >
    > }


    This can be reduced to:

    public class Display {
    public static void puts(String... args) {
    for (String arg : args)
    System.out.println(arg);
    }
    }

    (Uses variable arguments and the for-each loop, both features of Java 5
    and above).

    > import com.myorg.utils.Display;
    >
    > public class TestPuts {
    >
    > public static void main( String[] args ) {
    > puts( "A single string test." );
    > // This is specifically where I seem to be having trouble
    > passing a
    > // String[] array to the puts( String[] args ) call
    > implementation.
    > // But maybe the implementation itself in the Display class
    > isn't
    > // the way to go?
    > puts( {
    > "This is line 1",
    > "This is line 2",
    > "This is line 3"
    > } );
    > }
    >
    > private static void puts( String[] args ) { Display.puts( args ); }
    > private static void puts( String arg ) { Display.puts( arg ); }
    >
    > }


    As others have said, this can be reduced to this:
    // No need for the general import if all you have is the static function
    import static com.myorg.utils.Display.puts;

    public class TestPuts {
    public static void main(String... args) {
    puts("A single string test.");
    puts("This is line 1",
    "This is line 2",
    "This is line 3");
    }
    }

    > Everything seems fine as far has the implementation goes in the
    > Display class. But maybe that's the wrong way to go about it? I
    > can't believe I have to use a fifty letter package name class method
    > to print a line to the console. (This is one of the things I hate
    > about Java, but anyway...)


    Perl tends more towards a procedural programming paradigm, while Java is
    more OOP. The act of printing to the console is theoretically rare in a
    Java app, over the act of printing to an unspecified stream, e.g. it
    could be a log or a console. So the console output stream is but one
    stream among many, that would only be set at some configuration time.


    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth

+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast