Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Return sys name value to var for query

Posted on 2006-10-30
5
Medium Priority
?
330 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
Six Sigma Control Plans

721 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