Link to home
Start Free TrialLog in
Avatar of GorGor1
GorGor1

asked on

simple script

I must be a retard since I can't even get this easy script to work:

With perl, I need to open the file "/etc/httpd/zipzap".  There will be two words in "zipzap" file that I need to save as variables.  The zipzap file has the format:

----------(beginning of file)
word1
word2
----------(end of file)

I need to then print them to the shell. (I will be doing other things with them which I already know how to do, I just want to print them to the shell to make sure the script is working.)

I want all the path information and everything else to be in the perl file.  I don't want to have to designate the path and filename of "zipzap" at the shell.  Thanks!  (feeling stupid)

Tim
ASKER CERTIFIED SOLUTION
Avatar of builder110697
builder110697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GorGor1
GorGor1

ASKER

If i wanted to print them to a webpage, would this work?

print "Content-type: text/html\n\n";
print "<HTML><body>";
print "$item[0], $item[1]";
print "</body></html>";

Thanks again  :o)


Seems right, but I would use as few print statements as I could.  Saves execution  time.

  print "Content-type: text/html\n\n<HTML><body>\n$item[0], $item[1]\n</body></html>\n";

or

  print "Content-type: text/html\n\n"
    . "<HTML><body>\n"
    . "$item[0], $item[1]\n"
    . "</body></html>\n";
Avatar of GorGor1

ASKER

One last question, could you slightly modify the script for the case that the file "zipzap" has the format of:

word1:word2

This way I can see the pattern in how to read individual variables from a text file.  Thank you much and the points are yours upon your reply  :o)

Thanks again,

Tim
 #!/bin/perl
  my $fname = "/etc/httpd/zipzap";
  print "Content-type: text/html\n\n<HTML><body>\n";
  open( TTT, "<$fname" ) || die "Could not open file $fname - $!";
  foreach ( <TTT> ) {
    chomp;
    my @array = split( /:/, $_ );
    foreach ( @array ) {
      print "<p>$_\n";
    }
  }
  close TTT;
  print "</body></html>\n";