in reply to split and tie::file

After this line:

my $archivo = 'test-pdf.tex';

$archivo contains the exact literal text, "test-pdf.tex". That means the literal text held in $archivo doesn't have "\begin{document}" anywhere in it, so there's nothing for split to work with.

If you printed the contents of $archivo, or the contents of @coment, you would see that the primary failure is right there. Also, it's unnecessary to chomp the lines. The default behavior for Tie::File is to auto-chomp, and then replace the record separator (usually '\n') behind the scenes as the line is written back to the file. If you want to completely remove '\n', you'll need to set Tie::File to override the default behavior. You probably don't want or need to do this, but if you do, it's handled by the autochomp => 0 option upon initiating the tie.

As for opening the key file, you actually need to use open, as in, "open my $fh, '<', $archivo or die $!;, and then read first line of the file as my $line = <$fh>; (for example).


Dave

Replies are listed 'Best First'.
Re^2: split and tie::file
by pablgonz (Initiate) on May 30, 2011 at 11:20 UTC
    many thank, but, woks (no perfect) but works,tried your coments, and post
      Try to make the comments you give me, but I do not understand the examples given in perldoc5, look elsewhere and so may help you open the file (correctly), and separate it into $preamble $document, modify $preamble (comment lines) to save the changes made in the $preamble (join?? to $document) and save the same file. Thank you very much for your time and help with this newbie in perl.