LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-07-2009, 09:10 PM   #1
von_vea
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Rep: Reputation: 0
linux command inside perl script


Hi All,

I have a perl script named if3.pl pls. see below contents:

------------------------------------------------------
#!/usr/bin/perl -w

$today = `date | awk '{print \$1}'`;

if (($today eq 'Sat') or ($today eq 'Tue'))
{
$do = "Its saturday or tuesday";
}
else
{
$do = "Work!";
}

print "$do\n";
print "$today\n";
------------------------------------------------------

When I ran that script, these are the result.

------------------------------------------------------
$ perl if3.pl
Work!
Tue

------------------------------------------------------

I am expecting "Its saturday or tuesday" since the $today variable has "Tue".

But I have a hint that $today is not only having a value of "Tue" but as well as the extra line after Tue.

------------------------------------------------------
$ perl if3.pl
Work!
Tue
<THIS IS THE EXTRA LINE>
------------------------------------------------------

Any idea how to remote the extra line from $today variable ?


Many Thanks in advance!
- Von
 
Old 09-07-2009, 09:30 PM   #2
gregorian
Member
 
Registered: Apr 2006
Location: India
Posts: 473

Rep: Reputation: 33
chomp($today=`date | awk '{print \$1}'`);
 
Old 09-08-2009, 12:15 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Why would one call 'awk' from Perl in the first place ?
 
Old 09-08-2009, 06:39 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
agree with Sergei, you could have user
`date +%a`
 
Old 09-08-2009, 08:25 AM   #5
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,095
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
or even kept it in perl

$today = (split(" ", localtime()))[0];
 
Old 09-08-2009, 02:54 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
If we are talking about Perl and date/time manipulation, a good place to start from is: http://datetime.perl.org/?Modules .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perl inside a shell script baidym Linux - Newbie 2 05-05-2008 07:42 PM
How to acess Variable defined in perl script inside an awk call sumin Programming 3 04-26-2007 06:19 AM
Getting PID from a system command in Linux perl script sumbabs Linux - General 1 03-03-2005 11:38 AM
calling a c++ binary inside a perl script Blue_muppet Programming 3 08-29-2004 12:31 AM


All times are GMT -5. The time now is 04:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration