Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

simple script

Posted on 2000-03-02
5
Medium Priority
?
235 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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

610 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