[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

return value from sub

Posted on 2000-02-10
1
Medium Priority
?
199 Views
Last Modified: 2010-03-05
I want to write a sub which simply gets a string_1 and returns another string_2 after evaluating something with string_1.
For example:

test ($string_x);

sub test {
 my $string_1 = shift;
 if ($string_1 eq "") {
    return "no value";
 }
 else {
    return "has value";
 }
}
0
Comment
Question by:Stapman
1 Comment
 
LVL 3

Accepted Solution

by:
guadalupe earned 150 total points
ID: 2507850
Try this:

$result = &test ($string_x);

sub test {
 my $string_1 = shift;
 if ($string_1 eq "") {
    return "no value";
 }
 else {
    return "has value";
 }
}

The & before the call to the sub test is not necessary but its a little more correct codeing.  It seems stupid but some day you'll be thankfull when trying to find a call to a sub as it will be more identifiable.  It will also save perl the trouble of guessing what you want which it is very good at but not infalable.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question