Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

create .ncx files

by virudinesh (Acolyte)
on Jan 08, 2013 at 05:17 UTC ( #1012159=perlquestion: print w/replies, xml ) Need Help??
virudinesh has asked for the wisdom of the Perl Monks concerning the following question:

open(FH,"+>toc1.ncx"); $OH1 = select(FH); open (FILE,'b.txt') or die "$!"; while (<FILE>) { if (m/^(ISBN Number|book title|Cover|Half|Title|Copyright|Content|P +reface):(.*)/) { push(@arr,$2); } } #print @arr; my $i=0; print '<?xml version="1.0" encoding="UTF-8"?>'."\n"; print '<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://">'."\n"; print '<ncx version="2005-1" xml:lang="en" xmlns="http://www.daisy">'."\n"; print '<head>'."\n"; print '<meta name="dtb:uid" content='."$arr[$i++]".'/>'."\n";#ispn + no print '<meta name="dtb:depth" content=""/>'."\n"; print '<meta name="dtb:totalPageCount" content=""/>'."\n"; print '<meta name="dtb:maxPageNumber" content=""/>'."\n"; print '</head>'."\n"; print '<docTitle>'."$arr[$i++]".'<text></text></docTitle>'."\n"; print '<navMap>'."\n"; print '<navPoint id="NavPoint-" playOrder="1"><navLabel><text>'."$a +rr[$i++]".'</text></navLabel><content src=".html"/></navPoint>'."\n"; print '<navPoint id="NavPoint-1" playOrder="2"><navLabel><text>'."$a +rr[$i++]".'</text></navLabel><content src="Cover.html"/></navPoint>'. +"\n"; print '<navPoint id="NavPoint-2" playOrder="3"><navLabel><text>'."$a +rr[$i++]".'</text></navLabel><content src="Title.html"/></navPoint>'. +"\n"; print '<navPoint id="NavPoint-3" playOrder="4"><navLabel><text>'."$a +rr[$i++]".'</text></navLabel><content src="Fm-part.html"/></navPoint> +'."\n"; print '</navMap>'."\n"; print '</ncx>'."\n"; close FILE; select($OH1); close(FH);

Replies are listed 'Best First'.
Re: create .ncx files
by NetWallah (Canon) on Jan 08, 2013 at 06:07 UTC
    Is there a question here ?

    Please see Writeup Formatting Tips for information on how to post code correctly.

    You may also want to read up on how to use Arrays in perl. Information on this is available by typing "perldoc perlintro".

    I would also recommend adding the following to the top of every program you write:

    use strict; use warnings;
    If you need assistance debugging pyour program, please show the content of the file "b.txt" (at least the first few lines).

    It appears that you want to process a template with some data. An experienced programmer would use something like Template::Toolkit.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Re: create .ncx files
by LanX (Bishop) on Jan 08, 2013 at 06:25 UTC
    ehm ...???

    Parlez-vous Franšais?

    Cheers Rolf

Re: create .ncx files
by CountZero (Bishop) on Jan 08, 2013 at 17:26 UTC
    This is your actual program:
    open( FH, "+>toc1.ncx" ); $OH1 = select(FH); open( FILE, 'b.txt' ) or die "$!"; while (<FILE>) { if ( m/^(ISBN Number|book title|Cover|Half|Title|Copyright|Content|Preface) +:(.*)/ ) { push( @arr, $2 ); } }
    Your print statement will never execute as it was turned into a comment.

    So what is your question? Assume we know nothing about ".ncx"-files.

    Some very preliminary comments are:

    1. You are not using "use strict; use warnings;
    2. You are using two argument open rather than the three argument version.
    3. You are not using lexical filehandles.
    4. "Kidnapping" the standard out filehandle and pointing it to a file is probably a bad idea. It is better to use an explicit filehandle in your print-statements.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1012159]
Approved by rovf
and a moth chases the moon...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-04-22 03:12 GMT
Find Nodes?
    Voting Booth?