?
Solved

simple script

Posted on 2000-03-02
5
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

752 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