Solved

Return sys name value to var for query

Posted on 2006-10-30
5
300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now