Re: how to to find the "/" in a string
by davido (Cardinal) on Aug 31, 2012 at 18:49 UTC
|
The answer to the specific question you ask can be found in the first section of perlrequick:
Finally, the // default delimiters for a match can be changed to arbitrary delimiters by putting an 'm' out front:
"Hello World" =~ m!World!; # matches, delimited by '!'
"Hello World" =~ m{World}; # matches, note the matching '{}'
"/usr/bin/perl" =~ m"/perl"; # matches after '/usr/bin',
# '/' becomes an ordinary char
But so you do less work up front, and endure less pain in the longrun, you might benefit from one of the many HTML parsers on CPAN.
| [reply] [d/l] |
Re: how to to find the "/" in a string
by ww (Archbishop) on Aug 31, 2012 at 18:39 UTC
|
Homebrewed html parsers are rarely as good as homebrewed beer... even after considerable aging.
Suggest you check the available modules with "parse" and/or "html" in their names; read their docs or at least each precis; and then pick one.
Update: just checked. In less than 2 months, you've posted nearly 50 questions. Perhaps you've seen this advice before in reply to one or more of them: study a good introductory text ("Learning Perl" for example); read the tuts here and also look around the Monastery for highly regarded, free tuts available at some (emphasis, "some;" as not all are worth the powder to blow them to hell) on-line college level tuts or courses; and study (hint: google site:perlmonks.org terms terms terms... or Super Search here) nodes that show how others dealt with your problem(s). | [reply] |
Re: how to to find the "/" in a string
by AnomalousMonk (Archbishop) on Aug 31, 2012 at 19:23 UTC
|
robertw: Please use <c> ... </c> or <code> ... </code> tags to enclose things like "aug</td>" or aug</td> that will otherwise render as HTML (since they include valid HTML tags!). (Didn't your post appear a bit strange to you when you previewed it?) Please see Markup in the Monastery and Writeup Formatting Tips.
| [reply] [d/l] [select] |
|
|
Thanks guys:), the ironic statements are well deserved yes I knowxD, and I did not notice the missing tags, my apologies for that
| [reply] |
Re: how to to find the "/" in a string
by philiprbrenan (Monk) on Aug 31, 2012 at 21:39 UTC
|
Here is a start. The regular expression gets the size of the array returned by the regular expression, which uses () to enclose the text to be searched for and /g to find all the occurences.
use feature ":5.14";
use warnings FATAL => qw(all);
use strict;
my $h = "aaa bbb ccc aaa aaa";
say scalar (() = $h=~m(aaa)g);
Produces
3
| [reply] [d/l] |
Re: how to to find the "/" in a string
by Kenosis (Priest) on Aug 31, 2012 at 19:32 UTC
|
$count =()= $html =~ m{aug</td>}g;
print $count;
Update: Didn't see AnomalousMonk's posting already mentioning this... | [reply] [d/l] |
Re: how to to find the "/" in a string
by BrowserUk (Patriarch) on Aug 31, 2012 at 18:18 UTC
|
Pull hard. When it breaks, where the slash in the string was will be obvious :)
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP Neil Armstrong
| [reply] |
Re: how to to find the "/" in a string
by cheekuperl (Monk) on Sep 03, 2012 at 03:28 UTC
|
how to to find the "/" in a string
perl -e '$str=q (usr/bin); print index($str,q(/))."\n";'
The output is
3
| [reply] [d/l] [select] |
Re: how to to find the "/" in a string
by pvaldes (Chaplain) on Aug 31, 2012 at 18:30 UTC
|
Not sure if I'm understanding the problem. You can search for a special character putting a "\" before "my_special_character"
count=0,
while ($html =~ [aug<\/td>]g) { $count++ }
| [reply] [d/l] |
|
|
count=0,
while ($html =~ [aug<\/td>]g) { $count++ }
Please don't post code that won't work – or, in this case, even compile. (Or if the code is untested, please flag the fact prominently.) A beginning Perler, even one as reluctant as robertw to read basic documentation, deserves better of us.
>perl -wMstrict -le
"my $html = 'xxx aug</td> yyy aug</td> zzz';
;;
my $count = 0;
while ($html =~ m[aug</td>]g) { $count++ }
print $count;
;;
my $count2 =()= $html =~ m{ aug</td> }xmsg;
print $count2;
"
2
2
| [reply] [d/l] [select] |