Re: quick perl question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Steven W. Orr [steveo@xxxxxxxxxxx] wrote:
> On Tuesday, Oct 21st 2003 at 11:44 -0400, quoth Jake McHenry:
> 
> =>Hi everyone, this is a pretty simple question I believe.. but I can't seem
> =>to get it...
> =>
> =>I have a perl script that does a system call to get the date.... everything
> =>works fine, but the returned date has a line return character and I can't
> =>get rid of it... here's my perl script..
> =>
> =>$date = `/bin/date +%Y%m%d`;
> =>
> =>I've tried system("/bin/date ... ");
> =>and exec("/bin/date....");
> =>
> =>all return the date with the line character... how can I get rid of it?
> 
> The easy answer is:
> 
> chomp ($date);
> see: perldoc -f chomp
> 
> The correct answer is to not start a seperate process just to find out 
> what time it is.

Right!  In other words, don't execute a system(or backticks or
exec) command when there is a perl internal function that can
give you the same thing.  What you need is the 'localtime'
function - do

   perldoc -f localtime

at a command prompt to display the excellent perldocs.

> 
> You should definitely buy the Perl Cookbook from O'Reilly. All your 
> questions will be answered.

Excellent suggestion!  I also regularly use "Learning Perl"
for quick easy reference, and "Programming Perl" for all
around Perl reference - all O'Reilly books.  But the
Cookbook is a must have IMHO.

-- 
Hardy Merrill
Red Hat, Inc.


-- 
Shrike-list mailing list
Shrike-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/shrike-list

[Index of Archives]     [Fedora Users]     [Centos Users]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat Phoebe Beta]     [Yosemite Forum]     [Fedora Discussion]     [Gimp]     [Stuff]     [Yosemite News]

  Powered by Linux