Re: bareword question



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

On Mon, 30 Mar 2009 09:39:25 -0700 (PDT) DaLoverhino <DaLoveRhino@xxxxxxxxxxx> 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
.