[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

simple script

Posted on 2000-03-02
5
Medium Priority
?
238 Views
Last Modified: 2010-03-05
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
0
Comment
Question by:GorGor1
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
builder110697 earned 80 total points
ID: 2578948
 #!/bin/perl
  my $fname = "/etc/httpd/zipzap";
  open( TTT, $fname ) || die "Could not open file $fname - $!";
  @item = <TTT>;
  close TTT;
  print $item[0];
  print $item[1];

However, you might need the values without the inherent linefeeds so you need to add something like:

  chomp $item[0];
0
 
LVL 1

Author Comment

by:GorGor1
ID: 2579020
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)


0
 
LVL 1

Expert Comment

by:builder110697
ID: 2580511
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";
0
 
LVL 1

Author Comment

by:GorGor1
ID: 2580574
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
0
 
LVL 1

Expert Comment

by:builder110697
ID: 2580640
 #!/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";

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question