bareword question

Discussion in 'Perl Misc' started by DaLoverhino, Mar 30, 2009.

  1. DaLoverhino

    DaLoverhino Guest

    Hello.

    I have a function that takes an array of quoted words:

    use strict;
    use warnings;
    my_function( "hello", "world!");

    I can do this:

    my_function qq(hello world!);


    is there anyway to tell perl, that any barewords after my_function
    (and my_function alone) should be treated as quoted words? So that I
    can just simply do this:

    my_function(hello world!);
     
    DaLoverhino, Mar 30, 2009
    #1
    1. Advertising

  2. On Mar 30, 9:39 am, DaLoverhino <> wrote:
    > I have a function that takes an array of quoted words:
    >
    > use strict;
    > use warnings;
    > my_function( "hello", "world!");
    >
    > I can do this:
    >
    > my_function qq(hello world!);
    >
    > is there anyway to tell perl, that any barewords after my_function
    > (and my_function alone) should be treated as quoted words?  


    No. Apples cannot be treated as oranges.

    Plus, strict and warnings and your barewords themselves will only
    pester you into using quotes.

    If you feel the need to use barewords, yet are still compelled to be
    warned about other bad coding decisions, then just turn off these
    modules at the "right" time:

    {
    no warnings 'syntax';
    no strict 'subs';
    my_function(bare, it, all)
    }


    but... if you say:

    {
    no warnings 'syntax';
    no strict 'subs';
    my_function(bare, it, all, girl!)
    }

    then you'll run into problems anyways.

    -Skye
     
    Skye Shaw!@#$, Mar 31, 2009
    #2
    1. Advertising

  3. DaLoverhino

    Ted Zlatanov Guest

    On Mon, 30 Mar 2009 09:39:25 -0700 (PDT) DaLoverhino <> wrote:

    D> I have a function that takes an array of quoted words:

    D> use strict;
    D> use warnings;
    D> my_function( "hello", "world!");

    D> I can do this:

    D> my_function qq(hello world!);

    D> is there anyway to tell perl, that any barewords after my_function
    D> (and my_function alone) should be treated as quoted words? So that I
    D> can just simply do this:

    D> my_function(hello world!);

    Make the parameters a string and split it on space in the function.

    use Data::Dumper;

    my_function("hello world!");
    my_function(qw/hello world/);

    sub my_function
    {
    my $p = shift @_;
    my @p;
    if (scalar @_)
    {
    @p = ($p, @_);
    }
    else
    {
    @p = split ' ', $p;
    }

    print "Parameters = " . Dumper(\@p);
    }

    Produces:

    Parameters = $VAR1 = [
    'hello',
    'world!'
    ];
    Parameters = $VAR1 = [
    'hello',
    'world'
    ];

    Doing it the way you suggest is unnecessary obfuscation.

    Ted
     
    Ted Zlatanov, Apr 1, 2009
    #3
  4. DaLoverhino

    Guest

    On Wed, 01 Apr 2009 13:19:42 -0500, Ted Zlatanov <> wrote:

    >On Mon, 30 Mar 2009 09:39:25 -0700 (PDT) DaLoverhino <> wrote:
    >
    >D> I have a function that takes an array of quoted words:
    >
    >D> use strict;
    >D> use warnings;
    >D> my_function( "hello", "world!");
    >
    >D> I can do this:
    >
    >D> my_function qq(hello world!);
    >
    >D> is there anyway to tell perl, that any barewords after my_function
    >D> (and my_function alone) should be treated as quoted words? So that I
    >D> can just simply do this:
    >
    >D> my_function(hello world!);
    >
    >Make the parameters a string and split it on space in the function.
    >
    >use Data::Dumper;
    >
    >my_function("hello world!");
    >my_function(qw/hello world/);
    >
    >sub my_function
    >{
    > my $p = shift @_;
    > my @p;
    > if (scalar @_)
    > {
    > @p = ($p, @_);
    > }
    > else
    > {
    > @p = split ' ', $p;
    > }
    >
    > print "Parameters = " . Dumper(\@p);
    >}
    >
    >Produces:
    >
    >Parameters = $VAR1 = [
    > 'hello',
    > 'world!'
    > ];
    >Parameters = $VAR1 = [
    > 'hello',
    > 'world'
    > ];
    >
    >Doing it the way you suggest is unnecessary obfuscation.
    >
    >Ted


    Why can't you quote like a normal human being?
    Whats all the "D> asdfasdf.as.sa.sa." crap.
    And you inject code and comments.
    None of it has dilineation from what your quoting.

    The most immature crap a poster can do.

    -sln
     
    , Apr 5, 2009
    #4
  5. DaLoverhino

    Guest

    On Wed, 01 Apr 2009 13:19:42 -0500, Ted Zlatanov <> wrote:

    >On Mon, 30 Mar 2009 09:39:25 -0700 (PDT) DaLoverhino <> wrote:
    >

    [cut]

    >sub my_function
    >{
    > my $p = shift @_;
    > my @p;
    > if (scalar @_)
    > {
    > @p = ($p, @_);
    > }
    > else
    > {
    > @p = split ' ', $p;
    > }


    Why do you post code with 1 space indentation???

    Are you seriously retarded or what?

    Why not just make it a one-liner?

    sub my_function{my $p = shift @_;my @p;if (scalar @_){@p = ($p, @_);}else{@p = split ' ', $p;}

    This is more readable.

    -sln
     
    , Apr 5, 2009
    #5
  6. DaLoverhino

    Ted Zlatanov Guest

    On Sun, 05 Apr 2009 22:28:13 GMT wrote:

    s> Why can't you quote like a normal human being?
    s> Whats all the "D> asdfasdf.as.sa.sa." crap.
    s> And you inject code and comments.
    s> None of it has dilineation from what your quoting.

    s> The most immature crap a poster can do.

    s> Why do you post code with 1 space indentation???

    s> Are you seriously retarded or what?

    I appreciate your interest in my quoting and coding style, not to
    mention my mental development. I assure you I have no doubts about
    yours.

    s> Why not just make it a one-liner?

    s> sub my_function{my $p = shift @_;my @p;if (scalar @_){@p = ($p, @_);}else{@p = split ' ', $p;}

    I could have, but it would have been ugly and obfuscated, as you have
    aptly shown.

    s> This is more readable.

    I don't like it much, but feel free to use that version in your own
    programs.

    Ted
     
    Ted Zlatanov, Apr 6, 2009
    #6
  7. Ted Zlatanov <> wrote:
    [Replying to your post because Mr. sln is somewhere near the bottom of
    my killfile]
    >On Sun, 05 Apr 2009 22:28:13 GMT wrote:
    >s> And you inject code and comments.


    Which is a good thing. Sane people put their comment next to the text
    they are commenting on. Then there is no confusion about what they are
    commenting on.

    >s> None of it has dilineation from what your quoting.


    Would you mind translating this sentence into English, please?

    >s> The most immature crap a poster can do.


    Actually it's Usenet standard.

    >s> Why do you post code with 1 space indentation???


    The question mark key on your keyboard is stuck.

    As to the content of the question: I personally would suggest 4 spaces
    of indentation or maybe even 8 if there is plenty of room.
    1 is indeed difficult to spot, although it might be justified to keep a
    max line length of 72 on deeply indentated code.

    >s> Why not just make it a one-liner?
    >
    >s> sub my_function{my $p = shift @_;my @p;if (scalar @_){@p = ($p, @_);}else{@p = split ' ', $p;}


    I would say because it's impossible to see the structure of that
    one-liner.

    sub my_function {
    my $p = shift @_;
    my @p;
    if (scalar @_) {
    @p = ($p, @_);
    } else {
    @p = split ' ', $p;
    }

    will make it immediately obvious that your great one-liner is actually
    missing the closing curly bracket.

    I don't always agree with Ted, but he is orders of magnitude saner than
    you as your inane rantings proof beyond any shadow of a doubt.

    jue
     
    Jürgen Exner, Apr 6, 2009
    #7
    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. Henry Law
    Replies:
    6
    Views:
    185
    Michel Rodriguez
    Apr 25, 2004
  2. mt35
    Replies:
    8
    Views:
    117
  3. Replies:
    4
    Views:
    384
    Michele Dondi
    May 10, 2006
  4. Gunnar Hjalmarsson

    Bareword errors?

    Gunnar Hjalmarsson, Nov 28, 2006, in forum: Perl Misc
    Replies:
    31
    Views:
    361
    Martijn Lievaart
    Dec 9, 2006
  5. Ronny
    Replies:
    11
    Views:
    335
    comp.llang.perl.moderated
    May 8, 2008
Loading...

Share This Page