in reply to How to output the words that you want that came thru an html file?

my $content = $response->content(); my @content = "$content"; my $introduction = grep (/Game Introduction - Marvel: Avengers Allianc +e/, @content); print "$introduction";

That is the same as saying:

my $content = $response->content(); my @content; $content[ 0 ] = $content; my $introduction = grep( /Game Introduction - Marvel: Avengers Allianc +e/, $content[ 0 ] ); print $introduction;

Or:

my $content = $response->content(); my $introduction = grep( /Game Introduction - Marvel: Avengers Allianc +e/, $content ); print $introduction;

Or more properly:

my $content = $response->content(); my $introduction = $content =~ /Game Introduction - Marvel: Avengers A +lliance/; print $introduction;

In other words, you don't have a list of "lines" in @content, just a single string.

You may want something like:

my @introduction = grep /Game Introduction - Marvel: Avengers Alliance +/, split /^/, $response->content(); print @introduction;

Replies are listed 'Best First'.
Re^2: How to output the words that you want that came thru an html file?
by stone_ice (Initiate) on May 04, 2012 at 06:17 UTC
    Yes, but how am I going to remove the h2 and /h2 tags?
      Looks like you need a HTML::Parser module.

      If that is too much, you can start with code like this:

      my @content = split /^/, $response->content(); my $introduction; for my $line (@content){ next unless ( $introduction ) ||= $line=~/Game Introduction - Marvel +: Avengers Alliance/; my $EndSection = $line=~/<\/section>/; local $_ = $line; # Make a copy, so we do not modify @content.. m|^\s*<[^/>]+>(.+)</| and $_=$1; # Zap tags on both sides, if any s|<[^>]+>||g; # Zap single </onetag> tags print; last if $EndSection ; }
      which , I suspect , is close to what you are looking for.

                   I hope life isn't a big joke, because I don't get it.
                         -SNL

        It displayed the output thanks to that sir,, hmm can you please explain to me the lines 17 up to 20? Im confused on that part...

        Thanks

        Update

        I've read the code but still confused specially on part line 20-21, if Im not mistaken it's a regular expression.. So far the out put is almost ok , the last thing I would want to do is arranging them in order.. now the output is like this:

        Game Introduction - Marvel: Avengers Alliance Welcome to the quick start guide for Marvel: Avengers Alliance, a supe +rhero role role playing game from Playdom. Recruit heroes, battle enemies and ta +ke on your friend’s teams in this action/strategy game.</p> <p>I would like to arrange them to be aligned at the left side removin +g the spacing at the Game Introduction and role part, what I would li +ke to achieve now is something like this.
        Game Introduction - Marvel: Avengers Alliance Welcome to the quick start guide for Marvel: Avengers Alliance, a supe +rhero role playing game from Playdom. Recruit heroes, battle enemies and tak +e on your friend’s teams in this action/strategy game.

        Is there a way that somehow arrange the text inside the string? or is it normal for this kind of output because the input came from an html file

        Thanks
      My favourite is HTML::TokeParser. This is a code fragment that finds the next <td> tag and then gets the text in the data cell.
      $stream = HTML::TokeParser->new( \$content ) $stream->get_tag('td'); $key = $stream->get_trimmed_text('/td');

      perl -e 'print qq(Just another Perl Hacker\n)' # where's the irony switch?