Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Gtk2 Visual Grep

by svenXY (Deacon)
on Jan 24, 2006 at 10:42 UTC ( [id://525146]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Gtk2 Visual Grep
in thread Gtk2 Visual Grep

Hi,
thanks again. The following patch adds capability of searching with regexes (I get some utf8 errors, but it works. Do you happen to know how to fix them?):
18c18 < my ($recurse, $name, $case,$linenums,$quick_start) =(0,0,0,0,0); --- > my ($recurse, $name, $case,$linenums,$quick_start, $use_regex) =(0,0 +,0,0,0); 21a22 > if( grep{/\bR\b/} @ARGV ){@ARGV = grep { $_ ne 'R' } @ARGV; $use_reg +ex = 1 }; 64a66 > my $vboxC3 = Gtk2::VBox->new(); 83a86,91 > my $checkbutton5 = Gtk2::CheckButton->new('Use RegEx'); > $checkbutton5->signal_connect( clicked => > sub{check_button_callback($checkbutton5, \$use_regex , +'use_regex')}); > $vboxC2->pack_start( $checkbutton5, 0, 0, 0 ); > > if($case){$checkbutton5->set_active(1);} 87c95 < $vboxC2->pack_start( $checkbutton4, 0, 0, 0 ); --- > $vboxC3->pack_start( $checkbutton4, 0, 0, 0 ); 91a100 > $hboxt->pack_start( $vboxC3, 0, 0, 0 ); 284,285c293,307 < if ($case){$regex = qr/\Q$search_str\E/} < else{$regex = qr/\Q$search_str\E/i} --- > if ($case){ > if ($use_regex) { > $regex = qr/$search_str/; > } > else { > $regex = qr/\Q$search_str\E/} > } > else { > if ($use_regex) { > $regex = qr/$search_str/i; > } > else { > $regex = qr/\Q$search_str\E/i; > } > }

Regards,
svenXY

Replies are listed 'Best First'.
Re^4: Gtk2 Visual Grep
by zentara (Archbishop) on Jan 24, 2006 at 13:36 UTC
    I "think" I found the answer to the "malformed utf8 errors". It probably only works for those using latin1 encoding. Possibly, it can be adjusted to use whatever encoding you use? Anyways, change the line which opens the file from
    open (FH,"<", $_); # to open (FH,"<:encoding(latin1)", $_);
    Anyways, it works for me in stopping the errors. I can't say how the regex search works in all it's complexity, for instance a really complex regex may need some special handling, but so far, so good. :-)

    Here is a complete patched snippet. I added another feature to skip search directories that begin with the number 1. (The code is commented out, but you may activate it). I store alot of html files for my categories, in 1DOCS, and I prefer not to delve into them on recursive searches. Modify to fit your needs.

    New script:


    I'm not really a human, but I play one on earth. flash japh
      Thanks a bunch, ++zentara!

      Last thing I was thinking about (except excluding dirs (for me it would be .svn dirs or so)) would be a start dir parameter. But I can easily do that myself.

      Regards,
      svenXY
Re^4: Gtk2 Visual Grep
by zentara (Archbishop) on Jan 24, 2006 at 12:07 UTC
    Hi, I believe I found a bug in your patch , which may be causing your problem. Your line
    > if($case){$checkbutton5->set_active(1);}
    probably should be
    > if($use_regex){$checkbutton5->set_active(1);}
    That would screw up the if-else clause, by cross-linking $case and $use_regex; but I'm still testing it. :-)

    I'm not really a human, but I play one on earth. flash japh
Re^4: Gtk2 Visual Grep
by zentara (Archbishop) on Jan 24, 2006 at 11:04 UTC
    My first guess would be to put "use utf8" at the top of the script. But you might want to post a new toplevel question for this? I will test it today and see what I can figure out.

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://525146]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found