For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > November 2005 > Trouble running a unix command with a subroutine call









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Trouble running a unix command with a subroutine call
AMT2K5

2005-11-24, 6:57 pm

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.

AMT2K5

2005-11-24, 6:57 pm

mkdir(&userID);

Ignore this posting, DOH!

Andrew McGregor

2005-11-24, 6:57 pm

AMT2K5 wrote:
> 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()?"
Purl Gurl

2005-11-24, 6:57 pm

Andrew McGregor wrote:

> AMT2K5 wrote:


[color=darkred]
> Unless you have a reason to do otherwise, use:


> mkdir(userID())


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.

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


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.

Be cautious to not "blindly" suggest code changes nor FAQ reading;
you most often end up with a foot in your mouth. Make sure you first
read and understand what you suggest, and if suggesting code changes,
compile and run your suggested code changes, first.

Purl Gurl
Mark Clements

2005-11-24, 6:57 pm

Purl Gurl wrote:
> Andrew McGregor wrote:
>
>
>
>
>
> 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
Tad McClellan

2005-11-24, 6:57 pm

AMT2K5 <Aaron.Train@gmail.com> wrote:

> 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


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
Purl Gurl

2005-11-24, 6:57 pm

Date: Fri, 25 Nov 2005 00:55:01 GMT
X-Newsreader: News Rover 11.0.0
Message-ID: <3cydnYZ4Ed-f_BvenZ2dnUVZ_tOdnZ2d@giganews.com>
Lines: 90
X-Trace: sv3-JIchFBaWOH/ 0XkwHCE3S9wIvVCLb+wyo2RMPrQ8x4jxwqFvonft
H/j+X2BwDQiDHQTdqmjYIuJXZ/6y!eZoUmrE2Ue5SmsCAqWVzZU/814DkzbglEsB/ KiNtzORsbd3rg4Fc6Bn2d192vnXRXQOcyXP3Qg==

X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32
Xref: number1.nntp.dca.giganews.com comp.lang.perl.misc:588864

Mark Clements wrote:

> Purl Gurl wrote:

(snipped)
[color=darkred]
[color=darkred]

[color=darkred]
> This doesn't deal with the prototypes issue, but which part of the faq
> do you disagree with?


I have snipped down the part which I find to be personal opinion rather
than fact. That snippet is above; ....While not....etc

That is a personal opinion written by the FAQ author, who continues
by suggesting &sub-routine syntax is a bug, although a deliberate
and documented part of perl core. He follows with a comment he,
personally, does not consider that syntax a feature; he argues a
case for his personal opinion, albeit it a wrong opinion.

Those types of comments have no place in a tech language FAQ;
it is a reflection of immaturity, if not ignorance.

Up until a year or so back, Perl FAQs also contained statements
indicating Windows is crap, Windows users are idiots, and such.
Those inappropriate comments were removed, I would like to believe,
after my complaining about those comments, for many years.

Use of &sub-routine() and sub-routine() are both documented
features of core, and both are very useful; both are needed.

What happens when ignorance (bigotry) is included in Perl FAQs
is many different notions. Foremost, readers are taught wrong,
if not bad, information which limits their skills. Another notion is
readers are "brainwashed" into believe of personal opinion rather
than a believe of factual information. Both of those notions leads
to readers writing very poor quality Perl programs because of
their stunted skills caused by ignorance in Perl FAQs.

Big picture is, and this does "seem" true, is a majority of fairly
new Perl programmers, least since the advent of Perl 5.x version,
a majority of those new people are "copy and paste" babies who
hold little knowledge of how to write real programs. Behind this
big picture are people, poorly skilled, poorly learned people, who
promulgate bad information taught to them, with religious zeal.
Otherwords, a majority of those populating the Perl Community
are parrots who repeat words, with no knowledge of what those
parroted words mean.

In comparison, you read Microsoft FAQs and they are extremely
professional, impart lots of technical information, are free of any
personal opinion, and certainly free of technological bigotry. In
this way, Microsoft and its program languages, are infinitely
superior to Perl programming; Microsoft has its act together.

You, personally, have fallen into this "parrot trap" created by
the Perl community. You provide code examples, code tests,
which are appropriate, but you completely missed what is
"wrong" with this FAQ; misleading personal opinion.

Most surprising, is my previous article stated, with precision,
what is wrong with this FAQ, yet you still do not understand
evidenced by your code examples, rather than discussion of
what is wrong with this FAQ,

"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."

So, there "it" is again for a second time. There is no doubt there are many
who cannot comprehend my statement being so brainwashed.

Stated differently, you are one of the "mindless minions" who
populate the Perl Community, which is not an insult but rather a
factual observation. You do not have to remain a mindless minion.

Written by me before, in many different ways,

"Do not blindly assume all to be right."

Purl Gurl
Purl Gurl

2005-11-25, 3:57 am

Purl Gurl wrote:

> "Do not blindly assume all to be right."


"Not only does the & form make the argument list optional, but it also disables any prototype checking
on the arguments you do provide. This is partly for historical reasons, and partly for having a convenient
way to cheat if you know what you're doing. See the section on "Prototypes" later in this chapter."

- Programming Perl, Schwartz, Christiansen & Wall

Those three are indicating, "...if you know what you are doing."

The hidden message of this FAQ author is,

"I do not want you to know what you are doing. You are to do what I tell you. My way is the only right way."

That attitude is expressed here daily, and has been expressed here for years and years.
Those who express that attitude, I immediately dismiss as mindless minions.

Who does not display that attitude? MOI, the most infamous and most imaginative Perl programmer ever!

Who is constantly trolled, insulted and told to be wrong? That would be me, of course! Why does this
happen? Because I am a talented and imaginative Perl programmer who threatens the egos of others,
if not cause those others to be insanely jealous of my skills.

Do I always get "it" right? NO.

To whom do I owe my beginnings in Perl? Randal Schwartz who is as much of a rebel as I.

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.

Nonetheless, I find the author of this FAQ to be intellectually insulting by his indicating
my method is wrong, especially after successfully using my method for over a decade.

Perhaps it is, I know what I am doing and the FAQ author does not?

So, which is better? Knowing what you are doing or blindly doing what another tells you to do?

Here is a simplified example of what can happen
when a Perl FAQ imparts bad information.

Pretend this is a case example of a need to perform
a series of complex mathematical calculations with
a single input number. Maybe sine, cosine, geometry,
trigonometry, calculus, whatever.

You want to calculate a variety of results based on
a single number input.

Run this sample script and question,

"Which syntax is best for these specific circumstances?"
"Does this FAQ impart all information needed?"
"Which syntax is more programmer error prone?"
"What the Hades happened?"
"Why does this FAQ not warn about what happened?"
"Why does this FAQ indicate to not use what works best?"

Purl Gurl

* There are deliberate syntax errors; don't bother trolling me on those
* but rather think, instead.

#!perl

@_ = (1);

×
÷

sub times
{ print "A: ", @_ * 2, "\n"; }

sub divide
{ print "B: ", @_ / 2, "\n"; }

print "\n";

times_2();
divide_2();

print "\n";

times_2(2);
divide_2(2);

sub times_2
{ print "C: ", @_ * 2, "\n"; }

sub divide_2
{ print "D: ", @_ / 2, "\n"; }

print "\n";

times_3();
divide_3();

print "\n";

times_3(3);
divide_3(3);

sub times_3
{ print "E: ", "@_" * 2, "\n"; }

sub divide_3
{ print "F: ", "@_" / 2, "\n"; }
axel@white-eagle.invalid.uk

2005-11-25, 3:57 am

Purl Gurl <purlgurl@purlgurl.net> wrote:
> 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

Andrew McGregor

2005-11-25, 3:57 am

Purl Gurl wrote:
> Andrew McGregor wrote:
>
>
>
>
>
> 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.
Purl Gurl

2005-11-25, 6:59 pm

axel wrote:

> Purl Gurl wrote:
[color=darkred]
[color=darkred]
> Are you the same person who suggested that people learn Perl 4
> before Perl 5 and C before C++?


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
lacking in imagination, you cannot develop a better method
of concealing a troll article.

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."

Rather humorous, that.

Purl Gurl
axel@white-eagle.invalid.uk

2005-11-26, 6:58 pm

Purl Gurl <purlgurl@purlgurl.net> wrote:
> axel wrote:


[color=darkred]
[color=darkred]
[color=darkred]
> 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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com