Solved

Return sys name value to var for query

Posted on 2006-10-30
5
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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

635 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