Trouble running a unix command with a subroutine call

A

AMT2K5

Hello, I am trying to do something quite simple. I want to make a
diretory on my unix account based on the scalar string returned by a
function call (which retrieves a user ID from a database and stores it
in a scalar string)

our $createDirectory = `mkdir &userID';

Tried something like the above command but to no avail do I have any
success.

Appreciate any help whatsoever. Thanks in advance.
 
A

Andrew McGregor

AMT2K5 said:
mkdir(&userID);

Unless you have a reason to do otherwise, use:

mkdir(userID())

perldoc -q "What's the difference between calling a function as &foo and
foo()?"
 
M

Mark Clements

Purl said:
In lieu of a factual basis for code changes, you should not suggest
changing of code. You do not know if @_ exists or not, nor do you
know the originating author's program circumstances.

Your advice may or may not be correct. It is not a good practice
to "blindly" suggest code changes.

In almost all cases, I read posters suggesting a sub-routine call
syntax change, not because they understand why, but rather simply
because they are acting a parrot; repeating what is said to them
without thought.


That syntax will bring up pages and pages of documentation with almost
all those pages, unrelated to this thread topic. Yours is an example of
"blindly" suggesting code; you created unwarranted problems.

I have found quoting pertinent information to be on-target and polite.

" What's the difference between calling a function as &foo and foo()?

When you call a function as "&foo", you allow that function
access to your current @_ values, and you bypass prototypes. The
function doesn't get an empty @_--it gets yours! While not
strictly speaking a bug (it's documented that way in the perlsub
manpage), it would be hard to consider this a feature in most
cases.

When you call your function as "&foo()", then you *do* get a new
@_, but prototyping is still circumvented.

Normally, you want to call a function using "foo()". You may
only omit the parentheses if the function is already known to
the compiler because it already saw the definition ("use" but
not "require"), or via a forward reference or "use subs"
declaration. Even in this case, you get a clean @_ without any
of the old values leaking through where they don't belong."


That FAQ is clearly FUBAR. That FAQ contains personal opinion rather
pure facts. The writer of that FAQ clearly has no clue and has resorted
to "parrot" speak.


C:\Documents and Settings\mark.HAWK>cat testsubs.pl
use strict;
use warnings;

my @data = qw(Mark likes eggs on toast);

firstsub ( @data );

sub firstsub {
my @args = @_;

print "first sub args: ".(join ",",@args)."\n";
secondsub();
&secondsub;
&secondsub();
}
sub secondsub {
my @args = @_;

print "second sub args: ".(join ",",@args)."\n";
}




C:\Documents and Settings\mark.HAWK>perl testsubs.pl
first sub args: Mark,likes,eggs,on,toast
second sub args:
second sub args: Mark,likes,eggs,on,toast
second sub args:


This doesn't deal with the prototypes issue, but which part of the faq
do you disagree with?

Mark
 
T

Tad McClellan

AMT2K5 said:
I want to make a
diretory on my unix account based on the scalar string returned by a
function call (which retrieves a user ID from a database and stores it
in a scalar string)


A "string" is the same as a "scalar string".

Every string is a scalar.

Why did you think you needed a "scalar" qualifier twice?

our $createDirectory = `mkdir &userID';
^ ^
^ ^ What's with the funny quotes?

You should copy/paste *real code*.

Have you seen the Posting Guidelines that are posted here frequently?

You should prefer lexical variables (my) over package variables (our),
so why do you feel that you needed a package variable?

Function calls are not interpolated in double quotish strings.

Use Perl's mkdir() function rather than shelling-out:

perldoc -f mkdir
 
A

axel

Purl Gurl said:
Purl Gurl wrote:
During all my years of Perl programming, not once have I used subroutine() syntax.
I always use &subroutine() syntax. I have found &subroutine() syntax to be safer,
less prone to error and significantly more convenient. Is my method right for all? NO.
Is my method right for all circumstances? NO.

Are you the same person who suggested that people learn Perl 4
before Perl 5 and C before C++?

Axel
 
A

Andrew McGregor

Purl said:
In lieu of a factual basis for code changes, you should not suggest
changing of code.

Unless you post details to the FAQ that most people agree with, allowing
the OP to make their own decision whether or not it is relevant to them.
 
A

axel

Purl Gurl said:
axel wrote:
Your question is a display of ignorance. You already know I am
that person. Why are you asking a question for which you know
the answer? Your reason is simple. You are trolling and are so

Er, no I did not... it was just your style which seemed similar.
lacking in imagination, you cannot develop a better method
of concealing a troll article.

Sorry, I have no need to troll.. someimes inspired by whatever is
in the air and whatever I have drunk, I might post something which
is out of place... but deliberately troll, no.
I also suggest people learn to walk before learning to run. However,
there are those whose egos dictate they boast of running skills before
being able to walk. Those egotistical people always fall flat on their
faces, and alway end up with a foot in their mouths, which is comical.
You have written, paraphrased,
"Learn to write before you learn the alphabet."

No... that is not what I wrote or anything remotely like it.

Axel
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top