Hello again folks,

My apologies for not indicating where line 25 is. Here's the code with the problem line indicated. How would I initalise the problem variable?

Use of unitialized value in array element at controlflow.plx (#1) line 25 (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a + mistake. To suppress this warning assign a defined value to your var +iables. #!/usr/bin/perl # controlflow.plx =head1 DESCRIPTION Program will read in an html file and add word spacing style attribut +es to header, paragraph and list tags. and print out doc in DOS window. Presence of tags/attributes will be +tested for via an 'if-else' control structure. =head2 ALTERNATIVE FILE OPENING CODE $htmlFile = "E:/Documents and Settings/Richard Lamb/My Documents/HTML +/dummy.html"; open (INFILE, "<".$htmlFile) or die("$!: Can't read source file!\n"); =cut use warnings; use diagnostics; use strict; # Declare and initialise variables. my @htmlLines; # Open HTML test file and read into array. open (INFILE, "E:/Documents and Settings/Richard Lamb/My Documents/HTM +L/dummy.html"), or die ("$!: Can't open this file.\n"); @htmlLines = <INFILE>; close (INFILE); # Check for attribute pattern in file if($htmlLines[my $i] !~ m/word-spacing:\s?[\d]+px/ig) # This is line + 25 { # Loop through file stored in array, inserting attribute foreach my $line (@htmlLines) { $line =~ s/(<h[1-6]\sstyle=.*)">/$1; word-spacing: 30px">/ig; # c +ase insensitivity and global search for pattern. $line =~ s/(<p\sstyle=.*)">/$1; word-spacing: 10px">/ig; $line =~ s/(<li\sstyle=.*)">/$1; word-spacing: 10px">/ig; } # Print modified file in DOS window for my $i (0..@htmlLines-1) { print $htmlLines[$i]; } } else { print "Attribute not in HTML file\n"; }

In reply to Control flow revisited by Tricky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.