Re: Array ref help
Chris Jones wrote: I am trying to pass an empty array by reference and populate it in a subroutine. I need it to be a 2-d array. I can't quite get it? Thanks! #!/usr/bin/perl use strict; my @Test; getReps([EMAIL PROTECTED]); for my $test_ref (@Test) { # print OUTFILE "@$test_ref\n"; print "@$test_ref\n"; } sub getReps { my ($refTest)[EMAIL PROTECTED];#assign two references # my @junk1 = [1,2,3]; # my @junk2 = [4,5,5]; # $refTest->[0] = @junk1; # $refTest->[1] = @junk2; # Square brackets signify an array reference, not an array my $junk1 = [1,2,3]; my $junk2 = [4,5,5]; $refTest->[0] = $junk1; $refTest->[1] = $junk2; } Cheers, Rob ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Array ref help
I am trying to pass an empty array by reference and populate it in a subroutine. I need it to be a 2-d array. I can't quite get it? Thanks! #!/usr/bin/perl use strict; my @Test; getReps([EMAIL PROTECTED]); for my $test_ref (@Test) { print OUTFILE "@$test_ref\n"; } sub getReps { my ($refTest)[EMAIL PROTECTED];#assign two references my @junk1 = [1,2,3]; my @junk2 = [4,5,5]; $refTest->[0] = @junk1; $refTest->[1] = @junk2; } Chris Jones, P.Eng. 14 Oneida Avenue Toronto, ON M5J2E3 Tel. 416 203-7465 Fax. 416 946-1005 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Using regular expressions to replace file text?
[Decided to top-post this time since Matt is.] Under Win32, you need to set binmode() on binary files: my $file = 'myImage.jpg'; # Opening binary file for read & write. open( IMAGE, "+<$file" ) or die "*** Trouble opening '$file' : $!\n"; binmode( IMAGE ); I would caution you though that you are always safer opening one file in Read mode and another file descriptor in Write mode. Then after you are done writing to the new file, close the file handles, then delete the old file, and rename the new file to the old file's name. This prevents various nastiness when in a multi-processing environment. And you don't clobber your original file until you have completely finished writing your replacement file which protects you from your own logic errors. Just a suggestion. while ( @ARGV ) { my $out = "$_.NEW"; open( IN, $_ ) or die "*** Trouble opening '$_' : $!\n"; open( OUT, ">$out" ) or die "*** Trouble creating '$out' : $!\n"; binmode( IN ); binmode( OUT ); # ... close( OUT ); close( IN ); unlink $_; rename $out, $_; } -- Mike Arms > -Original Message- > Matt Harp wrote: > > Thanks much for the info. > > One question though... > > I'm trying Perl because using the ReplaceRegExp stuff from Ant script > was corrupting my binary files. Now that I got Perl working, > I find out > that it's corrupting my binary files too :( > > I'm trying to do this stuff on a cvs ,v archive file that represents a > binary file (a .jpg for my testing). Doing a search/replce from my Vim > editor or from CodeWright works great and doesn't corrupt the > file. But > running that Perl command on that ,v file ends up with a > corrupted image > file when I do a Checkout from CVS. > > Are there special flags to tell Perl to stop corrupting my > binary files? > Am I hosed, and should just stick to do it from an editor? > > Thanks, > > -matt > mharp AT seapine DOT com > > > > > -Original Message- > > Mike Arms [marms AT sandia DOT gov] wrote: > > > > Matt Harp > > > Thanks Mike! > > > > > > I had tried single quotes but didn't think to try double quotes. > > > > > > I should probably be banned from this mailing list for such > > stupidity. > > > > > > but Ok, I'll push my luck... Any hints on how to make > this a script > > > that'll let me pass *.*? > > > > > > I seem to remember a reference to a way to tell it to work > > on multiple > > > files from the cmd-line but can't seem to find the forum post any > > > longer. > > > > > > Something like -file (name=*.*)? Or something... > > > > > > -matt > > > mharp AT seapine DOT com > > > > > > > > > > Mike Arms [marms AT sandia DOT gov] > > > > > > > > Matt Harp wrote: > > > > > This has to be an easy question to answer, but I've been > > > > looking and > > > > > hacking for a day now and can't figure it out. > > > > > > > > > > I want to just do search/replace on a set of files > > using regular > > > > > expressions. > > > > > > > > > > I have ActiveState 5.8.6 installed on WinXP, if that matters. > > > > > > > > > > I am trying it like this... > > > > > > > > > > perl -i.bak -pe s/^ext$/HARP/m fred.txt > > > > > > > > > > Perl help says that using m should result in ^,$ matching > > > > > beginning of line, end of line, but that's not what > > this does. It > > > > > matches any 'ext' string and replaces it with HARP. > > > > > I've tried \n instead also, but then that doesn't replace > > > > > anything. > > > > > > > > > > My second question is of course, how to make this into > > a script so > > > > > I can pass *.txt. I've found a couple scripts but > none of them > > > > > will even run w/o giving me errors. > > > > > > > > > > Any help on either issue would be immensley > > appreciated. I can't > > > > > take any more of this... > > > > > > > > > > Regards, > > > > > > > > > > -matt > > > > > mharp AT seapine DOT com > > > > > > > > I'm guessing that the issue is that you need to put the script > > > > portion in quotes: > > > > > > > > perl -i.bak -pe "s/^ext$/HARP/m" fred.txt > > > > > > > > Try that and let us know. > > > > > > > > -- > > > > Mike Arms > > > > Single quote work great in Unix/Linux. In fact I prefer them > > there as they prevent the "$" for being interpreted as an > > Environment variable reference. > > > > But under Win32, single quotes do not work. You have to use > > double quote. Fortunately, it does not try to do any command > > line substitutions. By the way, if you need to use double > > quotes in your script, I recommend using the qq() > construct. Example: > > > > perl -e "$i='foo'; print qq(This is a $i test\n);" > > > > On to your multiple files question, you may want Jenda > > Krynicky's "G" module: > > > > http://jenda.krynicky.cz/#G > > > > then try: > > > > perl -MG -i.bak -e "while (<>){ s/(^ext$/HARP/m; print; }" *.txt > > > > or recursive even: > > > > perl -MG=R -i.bak -e "while
RE: Using regular expressions to replace file text?
Thanks much for the info. One question though... I'm trying Perl because using the ReplaceRegExp stuff from Ant script was corrupting my binary files. Now that I got Perl working, I find out that it's corrupting my binary files too :( I'm trying to do this stuff on a cvs ,v archive file that represents a binary file (a .jpg for my testing). Doing a search/replce from my Vim editor or from CodeWright works great and doesn't corrupt the file. But running that Perl command on that ,v file ends up with a corrupted image file when I do a Checkout from CVS. Are there special flags to tell Perl to stop corrupting my binary files? Am I hosed, and should just stick to do it from an editor? Thanks, -matt [EMAIL PROTECTED] > -Original Message- > From: Arms, Mike [mailto:[EMAIL PROTECTED] > Sent: Wednesday, December 22, 2004 6:17 PM > To: Matt Harp; perl-win32-users@listserv.ActiveState.com > Subject: RE: Using regular expressions to replace file text? > > Matt Harp > > Thanks Mike! > > > > I had tried single quotes but didn't think to try double quotes. > > > > I should probably be banned from this mailing list for such > stupidity. > > > > but Ok, I'll push my luck... Any hints on how to make this a script > > that'll let me pass *.*? > > > > I seem to remember a reference to a way to tell it to work > on multiple > > files from the cmd-line but can't seem to find the forum post any > > longer. > > > > Something like -file (name=*.*)? Or something... > > > > -matt > > mharp AT seapine DOT com > > > > > > >Arms, Mike [marms AT sandia DOT gov] > > > Sent: Wednesday, December 22, 2004 5:40 PM > > > To: Matt Harp; perl-win32-users@listserv.ActiveState.com > > > Subject: RE: Using regular expressions to replace file text? > > > > > > Matt Harp wrote: > > > > This has to be an easy question to answer, but I've been > > > looking and > > > > hacking for a day now and can't figure it out. > > > > > > > > I want to just do search/replace on a set of files > using regular > > > > expressions. > > > > > > > > I have ActiveState 5.8.6 installed on WinXP, if that matters. > > > > > > > > I am trying it like this... > > > > > > > > perl -i.bak -pe s/^ext$/HARP/m fred.txt > > > > > > > > Perl help says that using m should result in ^,$ matching > > > > beginning of line, end of line, but that's not what > this does. It > > > > matches any 'ext' string and replaces it with HARP. > > > > I've tried \n instead also, but then that doesn't replace > > > > anything. > > > > > > > > My second question is of course, how to make this into > a script so > > > > I can pass *.txt. I've found a couple scripts but none of them > > > > will even run w/o giving me errors. > > > > > > > > Any help on either issue would be immensley > appreciated. I can't > > > > take any more of this... > > > > > > > > Regards, > > > > > > > > -matt > > > > mharp AT seapine DOT com > > > > > > I'm guessing that the issue is that you need to put the script > > > portion in quotes: > > > > > > perl -i.bak -pe "s/^ext$/HARP/m" fred.txt > > > > > > Try that and let us know. > > > > > > -- > > > Mike Arms > > Single quote work great in Unix/Linux. In fact I prefer them > there as they prevent the "$" for being interpreted as an > Environment variable reference. > > But under Win32, single quotes do not work. You have to use > double quote. Fortunately, it does not try to do any command > line substitutions. By the way, if you need to use double > quotes in your script, I recommend using the qq() construct. Example: > > perl -e "$i='foo'; print qq(This is a $i test\n);" > > On to your multiple files question, you may want Jenda > Krynicky's "G" module: > > http://jenda.krynicky.cz/#G > > then try: > > perl -MG -i.bak -e "while (<>){ s/(^ext$/HARP/m; print; }" *.txt > > or recursive even: > > perl -MG=R -i.bak -e "while (<>){ s/(^ext$/HARP/m; print; }" *.txt > > The globbing wouldn't be an issue if you were on Linux/Unix. :-) > > -- > Mike Arms > > > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Using regular expressions to replace file text?
Matt Harp > Thanks Mike! > > I had tried single quotes but didn't think to try double quotes. > > I should probably be banned from this mailing list for such stupidity. > > but Ok, I'll push my luck... Any hints on how to make this a script > that'll let me pass *.*? > > I seem to remember a reference to a way to tell it to work on multiple > files from the cmd-line but can't seem to find the forum post any > longer. > > Something like -file (name=*.*)? Or something... > > -matt > mharp AT seapine DOT com > > > >Arms, Mike [marms AT sandia DOT gov] > > Sent: Wednesday, December 22, 2004 5:40 PM > > To: Matt Harp; perl-win32-users@listserv.ActiveState.com > > Subject: RE: Using regular expressions to replace file text? > > > > Matt Harp wrote: > > > This has to be an easy question to answer, but I've been > > looking and > > > hacking for a day now and can't figure it out. > > > > > > I want to just do search/replace on a set of files using regular > > > expressions. > > > > > > I have ActiveState 5.8.6 installed on WinXP, if that matters. > > > > > > I am trying it like this... > > > > > > perl -i.bak -pe s/^ext$/HARP/m fred.txt > > > > > > Perl help says that using m should result in ^,$ matching > > > beginning of line, end of line, but that's not what this > > > does. It matches any 'ext' string and replaces it with HARP. > > > I've tried \n instead also, but then that doesn't replace > > > anything. > > > > > > My second question is of course, how to make this into a > > > script so I can pass *.txt. I've found a couple scripts but > > > none of them will even run w/o giving me errors. > > > > > > Any help on either issue would be immensley appreciated. I > > > can't take any more of this... > > > > > > Regards, > > > > > > -matt > > > mharp AT seapine DOT com > > > > I'm guessing that the issue is that you need to put the > > script portion in quotes: > > > > perl -i.bak -pe "s/^ext$/HARP/m" fred.txt > > > > Try that and let us know. > > > > -- > > Mike Arms Single quote work great in Unix/Linux. In fact I prefer them there as they prevent the "$" for being interpreted as an Environment variable reference. But under Win32, single quotes do not work. You have to use double quote. Fortunately, it does not try to do any command line substitutions. By the way, if you need to use double quotes in your script, I recommend using the qq() construct. Example: perl -e "$i='foo'; print qq(This is a $i test\n);" On to your multiple files question, you may want Jenda Krynicky's "G" module: http://jenda.krynicky.cz/#G then try: perl -MG -i.bak -e "while (<>){ s/(^ext$/HARP/m; print; }" *.txt or recursive even: perl -MG=R -i.bak -e "while (<>){ s/(^ext$/HARP/m; print; }" *.txt The globbing wouldn't be an issue if you were on Linux/Unix. :-) -- Mike Arms ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Using regular expressions to replace file text?
Matt Harp wrote: > Thanks Mike! > > I had tried single quotes but didn't think to try double quotes. > > I should probably be banned from this mailing list for such stupidity. > > but Ok, I'll push my luck... Any hints on how to make this a script > that'll let me pass *.*? > > I seem to remember a reference to a way to tell it to work on multiple > files from the cmd-line but can't seem to find the forum post any > longer. > > Something like -file (name=*.*)? Or something... Just noticed a module that may help - it seems to work. Win32-Autoglob [1.01 ] expand globs in @ARGV when the shell doesn't Otherwise you can use glob, File::Glob or File::DOS::Glob to handle the *.txt >>From: Arms, Mike [mailto:[EMAIL PROTECTED] >>Matt Harp wrote: >> >>>This has to be an easy question to answer, but I've been >> >>looking and >> >>>hacking for a day now and can't figure it out. >>> >>>I want to just do search/replace on a set of files using regular >>>expressions. >>> >>>I have ActiveState 5.8.6 installed on WinXP, if that matters. >>> >>>I am trying it like this... >>> >>>perl -i.bak -pe s/^ext$/HARP/m fred.txt >>> >>>Perl help says that using m should result in ^,$ matching >> >>beginning of >> >>>line, end of line, but that's not what this does. It >> >>matches any 'ext' >> >>>string and replaces it with HARP. >>>I've tried \n instead also, but then that doesn't replace anything. >>> >>>My second question is of course, how to make this into a >> >>script so I >> >>>can pass *.txt. I've found a couple scripts but none of >> >>them will even >> >>>run w/o giving me errors. >>> >>>Any help on either issue would be immensley appreciated. I >> >>can't take >> >>>any more of this... >>> >>> >>>Regards, >>> >>>-matt <[EMAIL PROTECTED]> >>>[EMAIL PROTECTED] >> >> >>I'm guessing that the issue is that you need to put the >>script portion in quotes: >> >> perl -i.bak -pe "s/^ext$/HARP/m" fred.txt >> >>Try that and let us know. -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Using regular expressions to replace file text?
Thanks Mike! I had tried single quotes but didn't think to try double quotes. I should probably be banned from this mailing list for such stupidity. but Ok, I'll push my luck... Any hints on how to make this a script that'll let me pass *.*? I seem to remember a reference to a way to tell it to work on multiple files from the cmd-line but can't seem to find the forum post any longer. Something like -file (name=*.*)? Or something... -matt [EMAIL PROTECTED] > -Original Message- > From: Arms, Mike [mailto:[EMAIL PROTECTED] > Sent: Wednesday, December 22, 2004 5:40 PM > To: Matt Harp; perl-win32-users@listserv.ActiveState.com > Subject: RE: Using regular expressions to replace file text? > > Matt Harp wrote: > > This has to be an easy question to answer, but I've been > looking and > > hacking for a day now and can't figure it out. > > > > I want to just do search/replace on a set of files using regular > > expressions. > > > > I have ActiveState 5.8.6 installed on WinXP, if that matters. > > > > I am trying it like this... > > > > perl -i.bak -pe s/^ext$/HARP/m fred.txt > > > > Perl help says that using m should result in ^,$ matching > beginning of > > line, end of line, but that's not what this does. It > matches any 'ext' > > string and replaces it with HARP. > > I've tried \n instead also, but then that doesn't replace anything. > > > > My second question is of course, how to make this into a > script so I > > can pass *.txt. I've found a couple scripts but none of > them will even > > run w/o giving me errors. > > > > Any help on either issue would be immensley appreciated. I > can't take > > any more of this... > > > > > > Regards, > > > > -matt <[EMAIL PROTECTED]> > > [EMAIL PROTECTED] > > I'm guessing that the issue is that you need to put the > script portion in quotes: > > perl -i.bak -pe "s/^ext$/HARP/m" fred.txt > > Try that and let us know. > > -- > Mike Arms > > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Using regular expressions to replace file text?
Matt Harp wrote: > This has to be an easy question to answer, but I've been > looking and hacking for a day now and can't figure it out. > > I want to just do search/replace on a set of files using > regular expressions. > > I have ActiveState 5.8.6 installed on WinXP, if that matters. > > I am trying it like this... > > perl -i.bak -pe s/^ext$/HARP/m fred.txt > > Perl help says that using m should result in ^,$ matching > beginning of line, end of line, but that's not what this > does. It matches any 'ext' string and replaces it with HARP. > I've tried \n instead also, but then that doesn't replace anything. > > My second question is of course, how to make this into a > script so I can pass *.txt. I've found a couple scripts but > none of them will even run w/o giving me errors. > > Any help on either issue would be immensley appreciated. I > can't take any more of this... > > > Regards, > > -matt <[EMAIL PROTECTED]> > [EMAIL PROTECTED] I'm guessing that the issue is that you need to put the script portion in quotes: perl -i.bak -pe "s/^ext$/HARP/m" fred.txt Try that and let us know. -- Mike Arms ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Using regular expressions to replace file text?
This has to be an easy question to answer, but I've been looking and hacking for a day now and can't figure it out. I want to just do search/replace on a set of files using regular expressions. I have ActiveState 5.8.6 installed on WinXP, if that matters. I am trying it like this... perl -i.bak -pe s/^ext$/HARP/m fred.txt Perl help says that using m should result in ^,$ matching beginning of line, end of line, but that's not what this does. It matches any 'ext' string and replaces it with HARP. I've tried \n instead also, but then that doesn't replace anything. My second question is of course, how to make this into a script so I can pass *.txt. I've found a couple scripts but none of them will even run w/o giving me errors. Any help on either issue would be immensley appreciated. I can't take any more of this... Regards, -matt [EMAIL PROTECTED] ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Tieregistry : display FILETIME
knackko wrote: > Hello people! > > I am working with Win32::Tieregistry in order to know the last > modifications on the registry (with the *Information* method). But i > fail to display it with print or printf. The module doc said : > > */Information > %info= $key->Information > @items= $key->Information( @itemNames ); > /*/Returns the following information about a Registry key: > *LastWrite* > A FILETIME structure indicating when the key was last modified and > packed into a Perl string./ > > I tried with > */printf("%04d/%02d/%02d%02d:%02d:%02d",$key->Information{"LastWrite"};/* > i've got : > > Use of uninitialized value in printf at regsurvey.pl line 50. > */ÐgçÄ/00/:00:00ÐgçÄ/00/:00:00/ * > * > Is there anybody who has successfully display the filetime? can you help > me? Firstly - always provide a complete and small executable snippet. This uses BigInt, but I've seen it done without resortig to that, but I think it's safer to use it. use Win32; use Win32::TieRegistry (Delimiter => '\\', ArrayValues => 0); my $key = 'HKEY_LOCAL_MACHINE\SOFTWARE\InterVideo'; my $Key = $Registry->{$key} or die "Can't read $key: $^E"; my @FT; if (1) {# pick one of these two methods my %items = $Key->Information; @FT = unpack 'II', $items{LastWrite}; } else { my @itemNames = ('LastWrite'); my @items = $Key->Information(@itemNames); @FT = unpack 'II', $items[0]; } my $epoch = FileTimeToEpoch (@FT); print scalar localtime $epoch, "\n"; exit; #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # FileTime: 100-ns intervals since January 1, 1601 (64 bits) # Epoch: seconds since January 1, 1970 (32 bits) sub FileTimeToEpoch { my $lsFT = shift; my $msFT = shift; require Math::BigInt; my $bias1601 = Math::BigInt->new(11644473600); # 1601->1970 bias (134774 days) my $nsecbias = Math::BigInt->new(1000); # secs->100-nsecs multiplier my $ls = Math::BigInt->new($lsFT); my $ms = Math::BigInt->new($msFT); my $epoch = Math::BigInt::numify ((($ms << 32) | $ls) / $nsecbias - $bias1601); return 0 if $epoch < 0; # in case prior to 1970/01/01 return $epoch; } __END__ -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Tieregistry : display FILETIME
Hello people! I am working with Win32::Tieregistry in order to know the last modifications on the registry (with the Information method). But i fail to display it with print or printf. The module doc said : Information %info= $key->Information @items= $key->Information( @itemNames ); Returns the following information about a Registry key: LastWrite A FILETIME structure indicating when the key was last modified and packed into a Perl string. I tried with printf("%04d/%02d/%02d%02d:%02d:%02d",$key->Information{"LastWrite"}; i've got : Use of uninitialized value in printf at regsurvey.pl line 50. ÐgçÄ/00/:00:00ÐgçÄ/00/:00:00 Is there anybody who has successfully display the filetime? can you help me? KnackKo ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: count of matches
You can also use this bizarre construction to capture just the count: $_ = "ABabcde12345BAABabcde1234blahblah5BA"; $count = () = $_=~ /(AB.*?BA)/g; print "I matched $count times\n"' the () between the two ='s forces the match to list context, and then THAT is forced to scalar context by setting it to $count. Whee! ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: count of matches
> How do I get a count of the number of matches a regex finds within a string? > > example: > > $_ = "ABabcde12345BAABabcde1234blahblah5BA"; > print $1 if /(AB.*?BA)/ ; > > Ultimate goal is to separate with \n. > > Terry Try this: $string = "ABabcde12345BAABabcde1234blahblah5BA"; $count = $string =~ s/(?<=AB)(.*?)(?=BA)/$&/g ; print "Count = $count\n"; I believe you can also use tr to count matches... -Erich- ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: count of matches
=~ m//g returns the number of matches if evaluated in list context so... $_ = "ABabcde12345BAABabcde1234blahblah5BA"; print $1 if /(AB.*?BA)/ ; becomes $_ = "ABabcde12345BAABabcde1234blahblah5BA"; @count=$_=~/(AB.*?BA)/g; print "I matched " . scalar @count . " times\n"; If you don't use the /g modifier it will only match once. Kind regards, Mark Anderson Service Improvement Project Level 2, 113 Dundas Street Edinburgh, EH3 5DE Tel: 0131 523 8786 Mob: 07808 826 063 > -Original Message- > From: vaughnte [SMTP:[EMAIL PROTECTED] > Sent: Wednesday, December 22, 2004 11:10 AM > To: [EMAIL PROTECTED] > Subject: count of matches > > *** WARNING : This message originates from the Internet *** > > > Howdy all, > > How do I get a count of the number of matches a regex finds within a > string? > > example: > > $_ = "ABabcde12345BAABabcde1234blahblah5BA"; > print $1 if /(AB.*?BA)/ ; > > Ultimate goal is to separate with \n. > > Terry > > ___ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB The Royal Bank of Scotland plc is authorised and regulated by the Financial Services Authority and represents The Royal Bank of Scotland Marketing Group. The Bank sells life policies, collective investment schemes and pension products and advises only on the Marketing Group's range of these products and on a With-Profit Bond produced by Norwich Union Life (RBS) Limited. This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
count of matches
Howdy all, How do I get a count of the number of matches a regex finds within a string? example: $_ = "ABabcde12345BAABabcde1234blahblah5BA"; print $1 if /(AB.*?BA)/ ; Ultimate goal is to separate with \n. Terry ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs