Hi Richard,
On Tue, 19 Apr 2016 04:58:32 + (UTC)
Richard Heintze via beginners wrote:
> I just love using viper mode in emacs to execute perl:
> .! perl -MPOSIX -pe ' BEGIN{ $np = qr{ \( (?: (?> [^()]+ ) | (??{ $np }) )*
> \) }x;$funpat = qr/$np/;} s/($funpat)=(.*)$/"$1=$3".eval($1)."$4"/ge'
>
> This command searches for a balanced set of parens (from the camel book)
> followed by an equal sign followed by any trailing garbage and evaluates the
> expression inside the balanced parans. so if you type (4*atan(1))=gobblygook
> and then execute the above VI/Ex command you get:
> 4*atan(1))=3.14159265358979
>
>
> Here is my failed attempt to do date arithmetic:
> (use Date::Calc ( ":all" ); use Date::Manip; my ( $date, $yy, $dd, $mm );
> $date = scalar localtime( ( time() - ( 24 * 60 * 60 ) ) ); $date)="" Can
> someone help me figure out how to use the eval function in my perl one-liner
> to evaluate date time arithmetic? Thanks,Siegfried
>
This is the Perl beginners mailing list and we aim to help beginners with
beginners question while encouraging best practices and code readability (see
http://perl-begin.org/tutorials/bad-elements/ for instance ). Your code is
not too readable and violates many best practices, so I'd rather not help you
with it, to avoid encouraging that.
Please write a better Perl program, in a separate file, with newlines and "use
strict;"/"use warnings;"/etc. and other best practices, (see the link) and you
can run it using :! perl ~/bin/my_filter .
I also don't understand which issue you're having with the date arithmetic.
Regards,
Shlomi Fish
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/