LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 08: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, 08:30 PM   #2
gregorian
Member
 
Registered: Apr 2006
Posts: 509

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

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Why would one call 'awk' from Perl in the first place ?
 
Old 09-08-2009, 05: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, 07:25 AM   #5
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

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

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

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


Reply



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 06:42 PM
How to acess Variable defined in perl script inside an awk call sumin Programming 3 04-26-2007 05:19 AM
Getting PID from a system command in Linux perl script sumbabs Linux - General 1 03-03-2005 10:38 AM
calling a c++ binary inside a perl script Blue_muppet Programming 3 08-28-2004 11:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:08 PM.

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
Open Source Consulting | Domain Registration