Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Using scalar variable in system set of commands

by dtbach (Novice)
on Nov 01, 2012 at 14:29 UTC ( #1001835=perlquestion: print w/ replies, xml ) Need Help??
dtbach has asked for the wisdom of the Perl Monks concerning the following question:

Seeking grate Perl Monks Wisdom

Just starting to learn perl, (as evident by my code and question, but everyone has to start somewhere).

print "Enter month (Abc) \n"; my $month = <STDIN>; chomp $month; system ("mailq \| grep \@ \| \$month \|sort +6 -7");

When using $month I get no output, however if I use Oct or Nov code works fine. Using perl -c and perlcritic.com there doesn't appear to be any errors, however must be something wrong with the code. Thank you, Darryl

Comment on Using scalar variable in system set of commands
Download Code
Re: Using scalar variable in system set of commands
by choroba (Abbot) on Nov 01, 2012 at 14:37 UTC
    By using the backslash, you prevent $month from being interpolated in the doublequotes. The shell then gets $month and tries to expand it - but there is no shell variable named $month.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Indeed. The backslashes before the pipes are also unnecessary.
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001835]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-09-18 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (116 votes), past polls