bareword question

D

DaLoverhino

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!);
 
S

Skye Shaw!@#$

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
 
T

Ted Zlatanov

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
 
S

sln

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
 
S

sln

[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
 
T

Ted Zlatanov

On Sun, 05 Apr 2009 22:28:13 GMT (e-mail address removed) 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
 
J

Jürgen Exner

[Replying to your post because Mr. sln is somewhere near the bottom of
my killfile]
On Sun, 05 Apr 2009 22:28:13 GMT (e-mail address removed) 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top