Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

line pro line match with Win32::Clipboard

by harryC (Sexton)
on Jun 12, 2007 at 12:57 UTC ( [id://620712]=perlquestion: print w/replies, xml ) Need Help??

harryC has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I am trying to match line pro line match in a text file
wich i get from the windows clipboard with Win32::Clipboard
My script does not see the next line.
I use the following code.
My script reloads everytime the whole file and i find always the first match.
My script loops.
Thks four your help
Harry

use Win32::Clipboard; $text = Win32::Clipboard::GetText(); my $zoektekst=$text; while ($zoektekst) { if ($zoektekst=~ m%\d{13}\s+CG1%) { #zoek het extern nummer in de t +ekst van het clipbord #print "ext nr: $&\n"; $_=$&; s%\s+CG1%%; $externnummer=$_; print "\nextern nummer: $externnummer\n"; } if ($zoektekst=~ m%INSZ\s\d{6}\s\d{3}\s\d{2}%) { $_=$&; s%INSZ\s%%; $inznummer=$_; print "inz nummer : $inznummer \n"; } }

Replies are listed 'Best First'.
Re: line pro line match with Win32::Clipboard
by citromatik (Curate) on Jun 12, 2007 at 14:05 UTC
    My script reloads everytime the whole file and i find always the first match.

    Think carefully what the script is doing:

    • You get your text to analyze with $text = Win32::Clipboard::GetText();
    • You are assigning the variable $text to the variable $zoektekst (completely useless, use your preferred variable in the first place: $zoektekst=Win32::Clipboard::GetText();
    • While the string in $zoektekst is not empty you will be looping. while ($zoektekst) {
    • If you match that regular expression, you copy the match in the $_ variable, delete one part and print another. The problem is that your substitution is made in the variable $_ that holds a copy of the previous match ($_=$&), but you are not changing the original variable $zoektekst at all. So, in the next iteration of the while loop, $zoektekst has the same content. You should be written:
      $zoektekst=~s%(d{13})\s+CG1%%; print $1;
    • The same for the next if

    Hope this helps

    citromatik

    Update: Be sure you provide an exit to the while loop.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-25 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found