perl syntax for use with urxvt and X clipboard


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers perl syntax for use with urxvt and X clipboard
# 1  
Old 03-02-2010
perl syntax for use with urxvt and X clipboard

I am trying to use the following perl code with urxvt terminal emulator to make using the X clipboard easier to deal with.

Code:
#! /usr/bin/perl

sub on_sel_grab {
    my $query=quotemeta $_[0]->selection;
    $query=~ s/\n/\\n/g;
    $query=~ s/\r/\\r/g;
    system( "echo -en " . $query . " | xsel -i -b -p" );
}

When utilising the script it does not behave as expected and also pastes the "-en" part of the echo command in the output.

For example, If it select "foo-bar" from urxvt and paste it into a text editor, it ends up as "-en foo-bar". I've been googling, reading perl documentation and trying to alter the code to make it work with no success.

the original information about it's usage can be found here: Rxvt-unicode - ArchWiki

perl -v
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
urxvt version = 9.06-3
I am using Debian Sid

Thanks
# 2  
Old 03-02-2010
You change the following in your script as follows.

Code:
system( "echo -en $query | xsel -i -b -p" );

Because,Perl will interpolate the variables inside the double-quotes("").
# 3  
Old 03-02-2010
Quote:
Originally Posted by vivekraj
You change the following in your script as follows.

Code:
system( "echo -en $query | xsel -i -b -p" );

Because,Perl will interpolate the variables inside the double-quotes("").
Thanks vivekraj,

I updated the code as suggested but it still adds "-en" to the pasted output?

I pasted the updated script into this thread using urxvt and this is how it turned out. Interestingly it appears to have added a carriage return halfway through line 5 as well.

Code:
-en #! /usr/bin/perl

sub on_sel_grab {
    my $query = quotemeta $_[0]->selection;
    $query =~ s/
/\n/g;
    $query =~ s/ /\r/g;
    system( "echo -en $query | xsel -i -b -p" );
}

Perhaps it is an issue with urxvt?

---------- Post updated at 07:59 PM ---------- Previous update was at 07:24 PM ----------

Thanks to a kind Arch Linux user who emailed me the solution as follows

----------

>$ echo -en foobar
>-en foobar

This is caused by dash which doesn't know -e (it's always on), you should use just "echo -n".

Debian's main shell switch to dash is a real bothersome one.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A Perl Syntax Question.

Greetings! Here's what I believe is a "simple one" for the community tonight ;) What I'm trying to do is assign a "true/false" value to a variable depending upon whether a named process (some-process) exists; and then test for this value in the succeeding logic. I banged my head against the... (2 Replies)
Discussion started by: LinQ
2 Replies

2. UNIX for Dummies Questions & Answers

Perl syntax

Query with perl syntax Aim: is to change a perl script to use a new file I was required to replace - entries \"$entries\" with -lib <full_path_to_filename> So in the code detector.pm sub rundetector { my $class = shift; mkdir($resultDirectory); my... (3 Replies)
Discussion started by: sa@@
3 Replies

3. Shell Programming and Scripting

Perl syntax

I'm a newbie to perl scripting. Can someone please explain the syntax below. Specifically what does -> and => do? $tz->site( => $site); (10 Replies)
Discussion started by: scj2012
10 Replies

4. Programming

Perl syntax question

Hallo everybody, I have a following problem - I'm doing a map funciont to fill in a HTML table and I want to use some radiobutton groups. Unfortunatelly, they are grouped by names, so I have to add some "counter" that will divide one row from another, and I'm using CGI.pm for generating the... (3 Replies)
Discussion started by: duskos
3 Replies

5. Programming

Syntax error in perl program.

Hi, i am running this code but i am getting syntax error #!/usr/bin/perl use warnings; use strict; use XML::LibXML; use XML::LibXML::Reader; use Data::Dumper; my $file; open( $file, 'DTC_Specification_transformed.xml'); my $reader = XML::LibXML::Reader->new( IO => $file ) or die... (1 Reply)
Discussion started by: veerubiji
1 Replies

6. Shell Programming and Scripting

PERL Syntax Errors

Hi, I am a newbie to PERL and working on a script. When running it I get a lot of compilation errors. The actual command in the program (which is within a case structure) is given below # This gives the actual count of inquires from a log file (It works fine when I type this on the... (2 Replies)
Discussion started by: nurani
2 Replies

7. Shell Programming and Scripting

perl syntax help

Im new at scripting and im trying to write a script using perl that will make sure there are 2 command line integer arguments and then check if the 2nd argument is greater than the first. i believe im close but still receive my error message even when i have 2 arguments and the second part gives me... (6 Replies)
Discussion started by: livewire06
6 Replies

8. UNIX for Advanced & Expert Users

perl explain syntax !!!

hi all i was going through some perl code i came across this line and i am not getting what is exactly going on .. $$this{localtion} = GetName->GetVarName("EXE_DIR") ; what is the red part doing in above code (2 Replies)
Discussion started by: zedex
2 Replies

9. Windows & DOS: Issues & Discussions

"Striping" the background of an Rxvt/Urxvt window in Cygwin

To get this: https://www.unix.com/members/silversleevesx-albums-incidental-shot-glass-picture127-termshot-rxvt-rootless.png out of Cygwin's rxvt, you have to tweak your /cygwin/etc/x11/app-defaults/rxvt file, which is here:... (0 Replies)
Discussion started by: SilversleevesX
0 Replies

10. Shell Programming and Scripting

Perl syntax for sed searches

I am aware that Perl has a lot of features that originally came from sed and awk. I have a pattern that I am using like this: sed -n '/|Y|/p' I want to do the same thing in Perl and be able to either save that value in some kind of variable or array or potentially write it out to a file. ... (11 Replies)
Discussion started by: masinick
11 Replies
Login or Register to Ask a Question