>>>>> "GS" == Gabriel Striewe <[email protected]> writes:
GS> my $status = system("emacsclient -n --eval '(progn (pop-to-buffer
(get-buffer-create \"*piped*\")))'");
GS> if($status!=0){ exit 1; }
GS> while(<STDIN>){
GS> system("emacsclient -n --eval '(with-current-buffer \"*piped*\"
(insert \"" . $_ . "\"))'");
GS> }
a first pass is for you to learn the qq{} alternate quote
operator. escaping " like you do is noisy and tricky. learn about these
in perlop. qq{} is like "" but you can put " inside without
escaping. you can use any delimiter you like but paired {} is among the
best (you can even have nested {} inside without escaping!). so those
lines would look like (untested):
my $status = system( qq{emacsclient -n --eval
'(progn (pop-to-buffer (get-buffer-create "*piped*")))'
});
system( qq{ emacsclient -n --eval
'(with-current-buffer "*piped*" (insert "$_"))'
});
notice how much easier they are to read and you can see the "" are for
emacs lisp and not for perl.
actually i just noticed the first one doesn't to any perl interpolation
so that could use q{} which is like ''. the second one needs double
quotish behavior since it interpolates $_.
another improvement would be to use a named variable in the while which
makes the code easier to read. i stay away from $_ unless it is required
or it has a major win. neither case applies here, so this is
better. also you don't chomp the input line and that may also screw
things up:
while( my $email = <STDIN> ) {
chomp $email ;
system( qq{ emacsclient -n --eval
'(with-current-buffer "*piped*" (insert "$email"))'
});
}
better formatting helps too. that code is now ready for you and others
to understand easily and maintain.
uri
--
Uri Guttman ------ [email protected] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/