Solved

Return sys name value to var for query

Posted on 2006-10-30
5
307 Views
Last Modified: 2012-08-14
Hi Experts,

What I thought would be a fairly simple task has me perplexed. I would like to determine the system name, store the value in a variable, and query the variable to determine a printer name.

Here's what I have:
#!/usr/local/bin/perl -TU
sub main {
  get_sysname;
}
sub get_sysname {
  say("getting name");
  $mysysname = `uname -n 2>&1`;
  chomp($mysysname);
  say("Sys Name is '$mysysname'");
  print $mysysname,"\n";
}


I execute the script, but am getting no output at all. I have both the say and the print command, in an attempt to get something out, but notta.  

Thanks in advance for your help !

-d
0
Comment
Question by:dcrosley
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 250 total points
ID: 17835114
The code you posted has 2 subroutines, neither of which is ever called.  Perl does not call the "main" subroutine (as in C).  Also, say is not a perl command, use print to display something.
Try this:

#!/usr/local/bin/perl -TU

get_sysname();

sub get_sysname {
  print "getting name";
  $mysysname = `uname -n 2>&1`;
  chomp($mysysname);
  print "Sys Name is '$mysysname'";
  print $mysysname,"\n";
}
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 17835121
The main problem I see is that you've defined 2 subroutines but never execute either of them.

What version of Perl are you using, is it Perl 6?  say() is not a built-in of Perl 5.
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 17835167
Adam,

I did a quick search and found that say() is implemented in Perl 6.

http://search.cpan.org/~dconway/Perl6-Say-0.04/Say.pm
0
 

Author Comment

by:dcrosley
ID: 17835212
What a dork. I can't beleive I didn't see that!

thanks, Adam!
0
 
LVL 39

Expert Comment

by:Adam314
ID: 17837290
FishMonger - I see the notes on say().  It saves an entire  "\n"  over print... was there much of a request from the user base for this!?!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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…

825 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