Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to import markup containing quotes?

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
lowercase baba
Posts: 13018
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic