I have a text file in the following format:
HEADER1
HEADER2
COL1 COL2 COL3 COL4 COL5
With data in each column. What I'd like to do is extract, for example, all data in COL2 and COL4...and write those columns to another file. I also need to ignore the headers that appear before the data...
...is the code:
#!/usr/bin/perl
open (WARNING, "/home/josh/warning.txt");
@arwarn = <WARNING>;
$stwarn = join('', @arwarn);
if($stwarn =~ m/LON(.*)TIME/) {
# I've also tried m/LON(.*)\nTIME and \r, etc and it works in some cases when those appear #
$coords = $1;
}
@metdata = split(/\s+/...
Thanks much, guys! That really helps. I seem to be losing the last longitude value in both methods, but that may be a consequence of my previous code. I'll have to look over things in more detail later. But it definitely gets me further than I was before.
Thanks so much!
...and all LONs the even elements.
Any suggestions and code assistance for how to use split to do this would be appreciated.
Thank you.
#!/usr/bin/perl
open (WARNING, "/home/josh/warning.txt");
@arwarn = <WARNING>;
$stwarn = join('', @arwarn);
if($stwarn =~ m/LON(.*)\nTIME/) {
$coords = $1;
}
I was thinking perhaps I could use a loop to store each value in an array, and then access the values by element. But I'd still need some help getting the right pattern.
It's been 2 years since I've done any work with regex in Perl so I'm hoping someone can offer a suggestion. I'd like to save all values in a text file (that's stored in array) between two keywords: "LON" and "TIME", into variables. The problem is I'd like to save each value to its own variable...
Thanks! I actually just did that, although a little differently but the same concept. In the one script I used $location = $_GET['foo'] and in the other script I put "script.php?foo=.'$location.'";
I appreciate it!
The hosting service I am using does not permit the use of registering globals. But I need to pass a variable with a constant value to other scripts that are called.
I've tried:
<?php
session_start();
$location = $_GET['location'] // Passed in from a webform.
session_register("location")...
Well, it turns out that it was indeed the host. The site claimed they allowed fopen but it turns out last week they decided to disable it for outgoing connections from their server.
I ended up getting it to work fine when I set it up locally.
Thanks very much for your help! Hopefully they...
Well, the problem still exists even if I use http to access the file I need (the files are stored both on FTP and HTTP). I also verified fopen is set to true.
Thanks for your reply. Unfortunately it isn't set to false. Someone else running a similar script is also having problems which is making me think it might be some sort of issue with the file server I'm accessing. Hmmm...
All of a sudden I'm getting the following errors when trying to execute a script:
Warning: fopen() [function.fopen]: connect() failed: Permission denied in /home/www/jmg498.freehostia.com/radar/crrdr.php on line 51
Warning...
Nevermind, figured it out!
<?php
if($temp > "271.16") {
$ratio = 12+2*(271.16-$temp);
}
$ratio = 12+(271.16-$temp);
print "The snow to liquid ratio is $ratio";
?>
This thread can be deleted. Thanks!
...on the code, but I just don't know how to format it correctly in PHP.
Any help is GREATLY appreciated! :) $temp is a variable passed in by a form.
<?php
if($temp > "271.16") {
$ratio == "12+2*(271.16-$temp)";
}
$ratio == "12+(271.16-$temp)";
print "The snow to liquid ratio is $ratio";
?>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.