Solved

Return sys name value to var for query

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

20 Experts available now in Live!

Get 1:1 Help Now