|
||||||
| Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi,
Just beginning perl and wanting to a perl script to do 2 things: First Pull a text file off a web site such as URL.com/sample.txt Then Text Parse the txt file to get figures for each line. The text file looks like this: username=DP data_down=8579.81 MB data_up=3894.36 MB free_data_down=22177.53 MB free_data_up=8311.49 MB I wanted to be able to return just the number for the query on each line. So If I ran the script "script.pl data_down" I would get just the figure 8579.81 printed. If possible can someone recommend or help me with some samples to achieve this with perl? |
| Sponsored Links |
|
|
|
|||||
|
That's pretty simple, but first of all I've got a few questions. Is the location of the text file on the same or a different server than your script? if it is on the same server you should just be able to "open" it...otherwise you'll need to use LWP::Simple and use "get".
Assuming that the file is on the same server you should be able to do something like this...(this is a CGI app...so instead of using CGI you'll just be able to use $ARGV[0] (that will contain the first argument passed to the script) Code:
#!/usr/bin/perl
use strict; use warnings;
use CGI;
my $cgi = CGI->new;
open(FILE, "data.txt") || die("Could not open file!");
my @contents=<FILE>;
close(FILE);
my $argv = $cgi->param('argv');
print "Content-type:text/plain\n\n";
foreach my $content (@contents){
if($content =~ m/^$argv=(.+)\sMB/){
print "$1\n";
}
}
__________________
Visit My Google Group Here: Web Development Innovation |
|
|||||
|
I realize dfp is not writing a CGI script...that is why i made the comment above....I also mentioned LWP::Simple...however I think that using a regex is quite a bit easier than the split function...if you're using the split function and splitting by an "=" then you'll still need to get rid of the " MB" at the end of each record (see dfp's example)
__________________
Visit My Google Group Here: Web Development Innovation |
|
|||
|
Quote:
|
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to style fonts of a text in a simple page? | c0de | Tutorials, Classes and Code | 3 | 09-15-2007 10:08 PM |
| Usage of array structures to increment letter instances of text | Yuriy M | C and C++ | 2 | 09-13-2007 10:49 AM |
| can someone help me with my c librarys? | bobwrit | C and C++ | 4 | 04-27-2007 06:19 PM |
| HTML Basic Formatting | clookid | Tutorials, Classes and Code | 14 | 03-06-2007 03:10 PM |
| Generate text with transparent background | AfTriX | PHP Tutorials | 1 | 01-08-2007 02:13 AM |