in reply to split function against a HTML code

How are you reading in the text of the file? And how are you doing the split of that text? You should be doing something like this:
my $file = 'blah.html'; # Slurp the file contents into one big string open my $fh, '<', $file or die "Cannot open $file: $!"; my $str = do { local $/; <$fh>; }; close $fh; # Split on '>' my @results = split '>', $str; print "Check :", $#results, "\n";
On another note, what is it you are trying to accomplish by splitting on '>'? Are you trying to get at each HTML tag, or a certain tag? Is this HTML trustworthy? Your code may not give you the result you expect if the HTML isn't valid and is missing a > or has an extra > in there. Just something to consider.

Replies are listed 'Best First'.
Re^2: split function against a HTML code
by greatshots (Pilgrim) on Nov 26, 2007 at 06:44 UTC
    open ( FH , "sample.html") or die "Unable to open the file :$!:"; while ( <FH> ) { chomp; my $line = $_; if ( $line =~ />KPI</i ) { print "$line\n----------------------\n"; my @line_split = ('<',$line); print "LINE_SPLIT :",@line_split,"-----",$#line_split,"\n"; my @result = map ( $_ ne '' , @line_split); print "Join :",join('-',@result); close (FH); } }
    I tried the above code. But the split does not split the input line as expected. :-/
      my @line_split = ('<',$line);
      looks like you neglected to call the split function at all: my @line_split = split('<', $line);
Re^2: split function against a HTML code
by greatshots (Pilgrim) on Nov 26, 2007 at 08:59 UTC
    Are you trying to get at each HTML tag
    Yes.