Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > Perl

Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-20-2007, 08:27 PM
dfp dfp is offline
Newbie
 
Join Date: Nov 2007
Posts: 1
Rep Power: 0
dfp is on a distinguished road
Default Perl text parse help (noob)

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-21-2007, 02:20 AM
fahlyn's Avatar   
fahlyn fahlyn is offline
Learning Programmer
 
Join Date: Nov 2007
Age: 25
Posts: 35
Rep Power: 3
fahlyn is on a distinguished road
Send a message via ICQ to fahlyn Send a message via AIM to fahlyn Send a message via MSN to fahlyn Send a message via Yahoo to fahlyn
Thumbs down

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";
   }
}
That should do what you need.
__________________
Visit My Google Group Here: Web Development Innovation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-21-2007, 11:11 PM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 87
Rep Power: 6
KevinADC is on a distinguished road
Default

He's not running a CGI script. He was also advised on another forum where to look to start coding such a script. LWP::Simple to fetch the page then parse it using the split() function.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-22-2007, 08:18 AM
fahlyn's Avatar   
fahlyn fahlyn is offline
Learning Programmer
 
Join Date: Nov 2007
Age: 25
Posts: 35
Rep Power: 3
fahlyn is on a distinguished road
Send a message via ICQ to fahlyn Send a message via AIM to fahlyn Send a message via MSN to fahlyn Send a message via Yahoo to fahlyn
Default

Quote:
Originally Posted by fahlyn View Post
you'll need to use LWP::Simple and use "get". ...so instead of using CGI you'll just be able to use $ARGV[0]
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-23-2007, 01:57 PM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 87
Rep Power: 6
KevinADC is on a distinguished road
Default

Quote:
Originally Posted by fahlyn View Post
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)
My bad. I didn't read all of your comments. Sorry.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 02:11 AM.

Contest Stats

dargueta ........ 128.00000
John ........ 127.00000
Xav ........ 107.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads