Re: require problems
by Shendal (Hermit) on Sep 19, 2000 at 21:23 UTC
|
The file must return TRUE as the last statement to indicate
successful execution of any initialization code, so it's
customary to end such a file with "1;" unless you're sure
it'll return TRUE otherwise. But it's better just to put
the "1;", in case you add more statements.
So, add this to the your stylesheet.pl file:
1; # return a one
Cheers,
Shendal
| [reply] [d/l] [select] |
|
|
When I'm feeling particularly evil, I'll use:
2;
or
"any true value will do";
or even
"0 but true";
Trivia question: why is the string "0 but true" special, and what's special about it?
-- Randal L. Schwartz, Perl hacker | [reply] [d/l] [select] |
|
|
Well, it's true in Boolean context but 0 in numeric context. Looking through the docs on fcntl, it looks like it's useful for the Perl calls that are wrappers to C system calls.
For example, if fcntl returns -1 to signify failure, Perl will massage that into undef. If it returns 0, Perl will use "0 but true" -- which means you can use it either numerically (C-style, expecting 0 to correspond to success) or Booleanifically (Perl-style, expecting 'true' to mean success).
Close enough?
| [reply] |
|
|
|
|
|
|
|
|
|
I think that particularly evil would be:
"false";
Cheers,
Shendal
| [reply] [d/l] |
|
|
|
|
my $true = "0 but true";
print "$true\n" if $true == 0;
| [reply] |
|
|
# return true
0 . 0;
| [reply] [d/l] |
|
|
|
|
Well, I fail to see how the string "0 but true" is any
more special than "any true value will do".
They're both simply strings that interpolate in a boolean context to true
how about:
0 . "true";
for something ever so slightly more "evil"...
(c8=
| [reply] [d/l] |
|
|
|
|
# grr...
"Why should version 5.6 make me do this in a module?"
Of course I like the capital letter "O"; too =)
--
$you = new YOU;
honk() if $you->love(perl) | [reply] [d/l] |
|
|
Excellent! Thank you. That was the problem.
Just,
Kurious
| [reply] |
Re: require problems
by japhy (Canon) on Sep 19, 2000 at 22:01 UTC
|
If you want evil return values: ( ) = 0;
Try that on for size. It's true. Isn't that criminal? :)
$_="goto+F.print+chop;\n=yhpaj";F1:eval | [reply] |
|
|
Well, not really *that* criminal --
it's a non-empty list...
<INCORRECT>
lists in scalar/boolean context return the number of
their elements.
</INCORRECT>
Update: I humbly acknowledge the folly of the above statement.
Should be:
list assignment returns the number of elements.
End Update
Thus:
perl -e '$val = () = 0; print $val';
prints 1 -- true!
| [reply] [d/l] |
|
|
lists in scalar/boolean context return the number of their elements.
Oh. Once again, trying to dispel the myth of that statement.
Repeat after me:
- You can never have a list in a scalar context...
- You can never have a list in a scalar context...
- You can never have a list in a scalar context...
Now, what's really happening is that you have a list assignment operator
in a scalar context, which is defined as having a return value of the number
of elements copied across, while giving a list context to the right side.
In this case, the right side is a simple expression, which gets turned into a list
of one element. So we get a "1" for the return value.
Once more, just so you remember:
- You can never have a list in a scalar context...
-- Randal L. Schwartz, Perl hacker
| [reply] |
|
|
No, that's not true. Lists do not exist in scalar or boolean
context.
$a = (3,2,1);
print $a; # 1
Read my article ("List is a Four-Letter Word") at
my web site for
stuff I'd rather not rewrite here.
perl -e '$val = () = (10,20,30); print $val'
prints 3.
$_="goto+F.print+chop;\n=yhpaj";F1:eval | [reply] [d/l] [select] |
|
|
| [reply] |
Re: require problems
by mirod (Canon) on Sep 19, 2000 at 21:26 UTC
|
Did you read the error message?
stylesheet.pl did not return a true value at addfather.pl line 4.
The problem is not in the require,
it's in stylesheet.pl. Just add a 1 or
return 1 in stylesheet.pl, at the end
of any code that is executed at compile time. That would
typically be before you start defining subroutines.
| [reply] [d/l] |