File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Perl and the fly likes How to import markup containing quotes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Perl
Bookmark "How to import markup containing quotes?" Watch "How to import markup containing quotes?" New topic
Author

How to import markup containing quotes?

Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
I'm trying to leave my markup in external files and bring it in like this:

# Read the content for the <head> element into a variable.
my $path = $markup_dir . '/head.htm';
open(FILE, $path) or die "Cannot read file $path: $!";
my $head = <FILE>;
close (FILE);

print $head;

The file contains the entire content for my <head> element. But then I find that my <head> element is not terminated, and in fact contains nothing at all:

<!DOCTYPE html><html><head><body><div id='leftbackground'>...

It seems like it must be having a problem with quoted strings inside the file (all are single-quotes). How do I fix this?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

It would be of TREMENDOUS help if you

a) posted a compete, runnable perl script that shows your problem. For someone to run your code, they'd have to figure out a bunch of issues just to see what you are seeing.
b) posted the input file - or at least, a small sample of it that illustrates your problem.

I was just able to write a perl script that reads this file:

this is a file
it has 'single quotes'
it has "double quotes"
it has `back quotes`
it works fine

and it printed this:
mars:hci:/export/home/hci/fbr1917/perlscripts>read.pl
this is a file
it has 'single quotes'
it has "double quotes"
it has `back quotes`
it works fine

The problem is not in the file or with the quotes. It must be something else...and we can't really tell without seeing all of it...

Now...i have a GUESS...but it is ONLY a guess, since I can't see your perl or your file.

The diamond operator only reads up to a newline. I am GUESSING your file contains some...so once it reaches the first one, it stops. If you want to read the entire contents of the file to a variable, you need to do something like this:


This while loop keeps reading a line at time, until there are no more lines, and appends them onto the $head2 variable. See if that works.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
Yes, that's right, thank you. For some reason I thought the syntax I was using would bring it all in in one go. Perl does take some getting used to. It's awfully cryptic and not altogether to my liking. Happily, my code is done, tested and working -- I used a loop to bring it in line by line -- and I can move on to other things now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to import markup containing quotes?