Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split problem

Status
Not open for further replies.

gm199

Programmer
Aug 9, 2001
37
US
Hi fellows.
I'm open a html file and want to use the upper part only, just above a unique mark (<!-- SEGUNDA COLUNA -->) but I cant get it to work!
This is the html:

<html><head><title>my page</title></head>
<body>
this is my text<br>
and more...
<!-- SEGUNDA COLUNA -->
this is junk<br>
and more junk...
</body></html>

What I did:

open(TEMPL,$feito);
#@linhas = <TEMPL>;
$linhas = <TEMPL>;
@linhas = split(/<!-- SEGUNDA COLUNA -->/,$linhas);
close(TEMPL);

Please help
 
I think you will find that after this:
Code:
$linhas = <TEMPL>;
$linhas contains the first line of the file (try printing it out). This is because the input record seperator by default is a newline and perl will, well, seaperate the input records by newline. To make perl go into 'slurp' mode, try this:
Code:
open(TEMPL,$feito);
{
#unset the input record seperator locally
local $/ = undef;

#slurp the file
$linhas = <TEMPL>;
}

#$/ should be the default value here

#do other stuff
@linhas = split(/<!-- SEGUNDA COLUNA -->/,$linhas);
close(TEMPL);

Will will@hellacool.co.uk
 
Try something like this:

#! /bin/perl
$infile = &quot;html.out&quot;;
open(HTML, &quot;$infile&quot;) || die &quot;error opening $infile $!&quot;;
@data=<HTML>;
while (@data) {
$_=shift @data;
if (m/^<!-- SEGUNDA COLUNA -->/){last}else{push @out, $_}
}
close HTML;
print &quot;@out\n&quot;;


-jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top