[11788] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5388 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 15 04:07:30 1999

Date: Thu, 15 Apr 99 01:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 15 Apr 1999     Volume: 8 Number: 5388

Today's topics:
    Re: $variables in <FILES> (Tad McClellan)
    Re: flocking question - worried (Graham Ashton)
    Re: getting mm/dd/yy from localtime() (Tad McClellan)
    Re: getting mm/dd/yy from localtime() (Abigail)
    Re: HELP:  PERL construct (Tad McClellan)
        How - Net::SSLeay + basic authentication ? krass@my-dejanews.com
    Re: How do I delete text in a file? <cramirez@gte.net>
        How do I format form input to DOS text (sort of) ??? (Mark Creelman)
    Re: how do I match all the "1"s in strings like 231451, (Tad McClellan)
        how to get the values of range in Excel (Ying-Gu Yang)
    Re: Interacting with a perl program in execution (Tad McClellan)
    Re: Looking for y2k code scanner for Perl code (Tad McClellan)
    Re: Matching whole word (Larry Rosler)
    Re: Need to print \n - Not do a carrage return <wyzelli@yahoo.com>
    Re: Need to print \n - Not do a carrage return (Larry Rosler)
    Re: Odbc won't work for database on network (Thomas Eichmann)
    Re: Printing a file <cramirez@gte.net>
    Re: Printing commas <cramirez@gte.net>
    Re: problem with push (Tad McClellan)
    Re: Reading from file into an array.... <cramirez@gte.net>
    Re: Reading from file into an array.... (Larry Rosler)
    Re: Sending data to HTML from perl script (Tad McClellan)
        SQL and the ODBC module leejola@my-dejanews.com
        stripping html tags suribond@my-dejanews.com
    Re: stripping html tags (Abigail)
        Trying to get the cgi script to print the date last upd (Loans2001)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 15 Apr 1999 01:11:51 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: $variables in <FILES>
Message-Id: <nes3f7.3d7.ln@magna.metronet.com>

Mark-Jason Dominus (mjd@op.net) wrote:
: In article <7f28o4$9cq$1@nnrp1.dejanews.com>,  <TimeSpinner@hotmail.com> wrote:
: >Is it possible to have a file which contains the text:
: >
: >and have a Perl Script read this file, and print it, automatically
: >substituting the $name and $address variables in?
: >
: >I've tried reading in the file, and processing the @array printing each line,
: >but it didn't do the interpolation, 

: Perl is full of these kinds of bugs.


   Yet Another Example:

      When I read in:       

$1000.00

      I want:

         the characters that matched the one thousandth set
         of parenthesis in the last successful pattern
         match, or undef (converted to the empty string)
         if there was no such successful match.

         concatenated with 2 zero characters.
   

     Oh yeah, and I don't want the newline either, so Perl
     should have auto-chomped it for me too.

     Isn't there an unused punctuation character (or sequence of
     characters) that can be made into a special variable that
     controls auto-chomping?


     I don't think that DWIM stuff that I keep hearing about
     has made much progress...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: 15 Apr 1999 06:16:19 GMT
From: billynospam@mirror.bt.co.uk (Graham Ashton)
Subject: Re: flocking question - worried
Message-Id: <slrn7hb11k.m8o.billynospam@wing.mirror.bt.co.uk>

In article <7f3ibb$f10$1@client2.news.psi.net>, Abigail wrote:
>[] 
>[] i.e. could the buffers be flushed in between calling flock() and
>[] close(), allowing another process to obtain a lock on the file before
>[] the first process has finished writing?
>
>Indeed. No doubt there's a system somewhere where this is not the case,
>but in general you can have unflushed buffers when releaseing the lock.

thanks to all for the quick and informative replies. I now feel much happier
about the robustness of my code.

-- 
Graham


------------------------------

Date: Thu, 15 Apr 1999 01:18:28 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: getting mm/dd/yy from localtime()
Message-Id: <4rs3f7.3d7.ln@magna.metronet.com>

RemarQ User (oekilla@aol.com) wrote:

: I need the current date with the mm/dd/yy
                                         ^^
                                         ^^
: format.

: Where do i look next?


   You don't say what you are using the date for, but you might
   consider looking ahead about 8 1/2 months or so.   

   :-)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: 15 Apr 1999 07:40:33 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: getting mm/dd/yy from localtime()
Message-Id: <7f455h$gov$1@client2.news.psi.net>

Tad McClellan (tadmc@metronet.com) wrote on MMLIII September MCMXCIII in
<URL:news:4rs3f7.3d7.ln@magna.metronet.com>:
// RemarQ User (oekilla@aol.com) wrote:
// 
// : I need the current date with the mm/dd/yy
//                                          ^^
//                                          ^^
// : format.
// 
// : Where do i look next?
// 
// 
//    You don't say what you are using the date for, but you might
//    consider looking ahead about 8 1/2 months or so.   
// 
//    :-)


Why? There are a lot of applications where 00 as year will be 
totally unambigous.

Maybe he's just keeping track when his car had its last inspection.



Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


------------------------------

Date: Thu, 15 Apr 1999 01:35:37 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: HELP:  PERL construct
Message-Id: <9rt3f7.3d7.ln@magna.metronet.com>

durai (durai@gotmail.eng.sun.com) wrote:

: I am trying to get the equivalent of the following in perl..

: nawk "/COMMENT_BEGIN/,/COMMENT_END/" $1  

: This will return the lines between the two tags inclusive.


   Perl comes with a utility named 'a2p' that converts
   awk into Perl.



-------------
echo '/COMMENT_BEGIN/,/COMMENT_END/' >test.nawk

a2p test.nawk

#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;
                        # this emulates #! processing on NIH machines.
                        # (remove #! line above if indigestible)

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
                        # process any FOO=bar switches

while (<>) {
    print $_ if /COMMENT_BEGIN/ .. /COMMENT_END/;
}
-------------


   The while() loop contains the interesting part.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 15 Apr 1999 05:32:04 GMT
From: krass@my-dejanews.com
Subject: How - Net::SSLeay + basic authentication ?
Message-Id: <7f3tkk$nln$1@nnrp1.dejanews.com>

When I go to the secure site orders10.datek.com, a small box pops up asking
for username/password. I managed to write Perl script using Net::SSLeay to
get to this page but how do I authenticate using Net::SSLeay in this
situation? Appears that the pop-up box is not a 'form' - or is it ?

Here is my code:

use Net::SSLeay;

$site = 'orders10.datek.com';
$port = 443;
$path = '/';
($page, $result, %headers) = &Net::SSLeay::get_https($site, $port, $path);
print "Result was `$result'\n";

foreach $h (sort keys %headers) {
    print "Header `$h'\tvalue `$headers{$h}'\n";
}


print $result;
print $page;


Here is the result:

Random number generator not seeded!!! Result was `HTTP/1.0 401 Unauthorized'
Header `Accept-ranges'	value `bytes' Header `Content-length' value `2334'
Header `Content-type'  value `text/html' Header `Date'	value `Thu, 15 Apr
1999 05:26:39 GMT' Header `Last-modified'  value `Wed, 24 Mar 1999 22:54:07
GMT' Header `Server' value `Netscape-Enterprise/2.01' Header
`WWW-authenticate'  value `basic realm="Datek Online"' ===================
Page follows ================= HTTP/1.0 401 Unauthorized<HTML> [here follows
html code saying that the server could not authenticate me - same if you
click Cancel 3 times using interactive browser]


Any help will be greately appreciated!

Krass

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Wed, 14 Apr 1999 21:46:08 -0700
From: Carlos Ramirez <cramirez@gte.net>
To: Gabriel Richards <grichard@uci.edu>
Subject: Re: How do I delete text in a file?
Message-Id: <7f3pr0$t51$2@news-1.news.gte.net>

Try:

local $/;
open TEXT, ">$textfile" or die;
open HTML,$filename or die;
$file = <HTML>;
$file =~ s/\<[^\>]+\>/ /g;
print TEXT $file;

OR

I have tried the HTML::Parse but currently it  has problems with parsing
tables and forms. Although I know there are other modules that handle forms
and tables. But if you want to completely take out all html tags...this should
do the job.

Carlos

Gabriel Richards wrote:

> Is there a function which will allow me to delete text from a file? I want
> to delete all the tags in an HTML file just leaving the content.
>
> Gabe



------------------------------

Date: Thu, 15 Apr 1999 05:12:49 GMT
From: rdcomp@sympatico.ca (Mark Creelman)
Subject: How do I format form input to DOS text (sort of) ???
Message-Id: <37157451.17056421@news1.sympatico.ca>



Hello All:

I am a semi-newbie who has spent many a night searching for this answer and I give up.

 I am receiving output from a form field into my script and saving it to a file on the server. It starts out in the form like so:

dogs over cats 
romans over greeks 
lions over tigers 
rats over mice
man over beast 

The file is being saved (and subsequentlty printed later)  in the format 
"     dogs over cats^Mromans over greeks^Mlions over tigers^M"......etc
using the following code:

open(BODY,">$Data/stuff.txt");
   	flock(BODY, '1');
      	print BODY "$FORM{'text'}\n";;
      	close(BODY);

I, of course want the output to be identical to the input, (ie. each item on a new line) with the ability to number each item, and
 choose how many of the items are displayed at once. 

Here's my script snippet for reading from file and printing out .

open(INF,"stuff.txt") or &dienice("Couldn't open stuff.txt for
        writing.");

    flock(INF, '1');	
    @lines = <INF>;
    close(INF);

    $number = @lines;

$track=$FORM{'numpicks'}; #the number of items printed, based on the value from another form. 

    for ($a = 0; $a < $track; $a++) {
 	$lines[$a] =s/[\cM\cB]//g
	$b=$a+1;
	print"<BR>$b ";
	print "$lines[$a]";
	 }

Which gives the result:

1 dogs over cats romans over greeks lions over tigers rats over miceman over beast 
2 
3 
4 
5

	When what I want is:
1. dogs over cats 
2. romans over greeks 
3. lions over tigers 
4. rats over mice
5. man over beast 

It works great, if I manually type it in DOS and upload it, or on the server using VI  , but not if it gets it input from the form.

	Any and all help would be appreciated. Sorry for long winded-ness, but I thought I would tell ALL the facts  

	Mark.


------------------------------

Date: Thu, 15 Apr 1999 01:30:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how do I match all the "1"s in strings like 231451,3132414131,etc?
Message-Id: <4it3f7.3d7.ln@magna.metronet.com>

SAM (same@minspring.com) wrote:
: Hello,
:              Here is a newbie question on perl re.
: How do I match a minimum of 2  and a maximum of 4 "1"s in strings like
: 2312312134
: 56132141313416512

: I used the following re

: $String =~ /[1]{2,4}/g;

: but this seem to match only successive occurances of "1"s.


   That is what it is _supposed_ to do.

   If they don't need to be consecutive, then don't require
   that they be consecutive    :-)



if ( $String =~ tr/1// >= 2   &&   $String =~ tr/1// <= 4)
   { print "'$String' is good\n" }
else
   { print "'$String' is bad\n" }


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 15 Apr 1999 05:37:49 GMT
From: yyang1@mail.earthlink.net (Ying-Gu Yang)
Subject: how to get the values of range in Excel
Message-Id: <3715794f.4301495@news.earthlink.net>

Hi!
I tried the following example in ActiveState's ActiveHelp. But it
would not print "XyzzyPerl" and the message "Use of uninitialized
value". So, my question is how to get the values of range in Excel.
Thanks in advance!

--------------------------------------------
# write a 2 rows by 3 columns range
$sheet->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ],
                                   [ 42,    'Perl',  3.1415  ]];

# print "XyzzyPerl"
$array = $sheet->Range("B8:B9")->{Value};
print $array[0][1] . $array[1][1];
--------------------------------------------

Ying-Gu Yang

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/  Ying-Gu Yang
_/  North Carolina State University
_/  yyang1@eos.ncsu.edu
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/



------------------------------

Date: Wed, 14 Apr 1999 20:28:20 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Interacting with a perl program in execution
Message-Id: <4rb3f7.3d7.ln@magna.metronet.com>

Peter Doyle (syzygy@indigo.ie) wrote:

:  I have program which requires a large file to be loaded and turned into
: a hash every time an operation is to performed. I want to have this hash
: in memory at all times and have the operations performed through cgi.
: The problem is a new instance of the hash has to be made every time the
: request comes in. Can I not have a process running which contains the
: hash and answer the requests???


   What you have described is called a "daemon".

   Armed with that, do a word search in the standard Perl
   docs (18 hits, including 1 FAQ).

   Probably should search CPAN for modules with "Daemon" in them.

   That might get you started.


   If the daemon must run on a computer that is not under
   your control, then this option may not be open to you...



: Any ideas?


   Perl FAQ, part 8:

      "How do I fork a daemon process?"


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 15 Apr 1999 02:20:10 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Looking for y2k code scanner for Perl code
Message-Id: <qe04f7.aj7.ln@magna.metronet.com>

Tom Karches (twk@unity.ncsu.edu) wrote:

: We would like to scan our internally developed Perl code for potential
: y2k coding problems. If someone has develped such a tool, I'd like to
: hear from you.


   Here's a simple and free one:

      while (<>) {
         print "check me!\n" if /19\$/;
      }

   :-)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 14 Apr 1999 23:35:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Matching whole word
Message-Id: <MPG.117f287fb499608a9898ba@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <19990414223845.17227.00000696@ng110.aol.com> on 15 Apr 1999 
02:38:45 GMT, Damon61 <damon61@aol.com> says...
> you use
> 
> if $whatever =~/^blah$/
> {
> }
> 
> the ^ in the beginning specifies that the word must start with "blah", and the
> $ at the end specifies that the word must end with "blah"

Ahem.  Welcome to the group.  This is a Perl newsgroup, and we like to 
see code written in syntactically correct Perl.  Yours isn't.

Also, your understanding of the anchors ^ $ and how they relate to this 
problem is quite faulty.

It would be a *very* good idea if you would test any code that you post, 
to make sure that it (1) compiles; and (2) helps to solve the stated 
problem.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Thu, 15 Apr 1999 13:52:16 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Need to print \n - Not do a carrage return
Message-Id: <YPdR2.6$jl2.4511@vic.nntp.telstra.net>

What you might want to do actually is output the HTML code for a line break
(ie <br>)  this will need to be escaped (ie \<br\>)

The browser typically will ignore the newline character...

I think this is what you are trying to achieve...

Wyzelli
Steve Springett wrote in message ...
>I am trying to actually print a \n to the browser but do not know how.  For
>example:
>
>print "<PARAM NAME = \"contents\" VALUE = \"First Line\nSecondLine\">\n";
>
>The above code is part of a larger piece that prints out HTML to the
browser
>and has a Java Applet.  I need to format the text for the applet using a \n
>but perl interprets it as the escape character it is.
>
>What I need the browser to see is:
><PARAM NAME="contents" VALUE="First Line\nSecondLine>
>
>How can I make this happen?
>
>
>
>
>




------------------------------

Date: Wed, 14 Apr 1999 23:44:10 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Need to print \n - Not do a carrage return
Message-Id: <MPG.117f2a94e7d40dd9898bb@nntp.hpl.hp.com>

In article <19990414223448.17227.00000695@ng110.aol.com> on 15 Apr 1999 
02:34:48 GMT, Damon61 <damon61@aol.com> says...
> try doing this
> print "<PARAM NAME = \"contents\" VALUE = \"First Line\\nSecondLine\">\\n";

The last double backslash should be single.  And all those backslashed 
double-quotes could be cleaned up by qq.

print qq{<PARAM NAME = "contents" VALUE = "First Line\\nSecondLine">\n};

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Thu, 15 Apr 1999 06:13:22 GMT
From: th.eichmann@gmx.net (Thomas Eichmann)
Subject: Re: Odbc won't work for database on network
Message-Id: <3715825a.2226093@news.eunet.ch>

The error message says the reason: it's obvious that another has the
mdb file opened in the exclusiv mode. When the other user closes the
file you should get access to the database.

Thomas

On Wed, 14 Apr 1999 19:26:37 -0400, qinqiang sun <qsun@kitco.ca>
wrote:
>Hi,
> I use perl Win32:odbc WinNT4.0. The Database is access97 and ODBC
>driver version is 3.50. If  use database on local driver there is no
>problem. When I tried to use database on network driver, I got error:
>                                                      **********
>Error:[-1032] [] "[Microsoft][ODBC Microsoft Access 97 Driver] The
>Microsoft Jet database engine cannot open the file '(unknown)'. It is
>already opened exclusively by
>another user, or you need permission to view its data."
>                                                     ************
>
>could you please give some clue so I can fix the problem>
>
>Thank you.
>
>Qinqiang
>
>
>



------------------------------

Date: Wed, 14 Apr 1999 21:34:16 -0700
From: Carlos Ramirez <cramirez@gte.net>
To: Andrew Branson <a_branson_1998@yahoo.com>
Subject: Re: Printing a file
Message-Id: <7f3p4o$t51$1@news-1.news.gte.net>

Try:

local $/;
open FILE,$filename or die "Could not open $fielname : $!\n";
$file = <FILE>;
print $file;


Andrew Branson wrote:

> I am sorry if this is a stupid question, but I am fairly new to Perl:  I
> there a way to read and print() an entire file as opposed to line by line?
> Thanks.
>
> Andy



------------------------------

Date: Wed, 14 Apr 1999 21:51:42 -0700
From: Carlos Ramirez <cramirez@gte.net>
To: gtdgm@hotmail.com
Subject: Re: Printing commas
Message-Id: <7f3q5e$t51$3@news-1.news.gte.net>

Try:
print join ',', @string_array;

or if you need the output save...

$string  = join ',', @string_array;
print $string;

Carlos

gtdgm@hotmail.com wrote:

> I have an array of strings.
>
> I want output to look like this:
> str1,str2,str3,str4
>
> Thus, between any two consecutive strings
> in the array a comma is printed.
>
> What is the easiest way to do this
> without using any loop?  Or is there such
> a way?
>
> Thanks ahead of time.
>
> -Godfrey Degamo
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own



------------------------------

Date: Thu, 15 Apr 1999 01:58:42 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: problem with push
Message-Id: <i6v3f7.3d7.ln@magna.metronet.com>

Elliot Slater (eslater@frinc.com) wrote:
: Here is code snipet:
: $MckShared  = "c:\perl\modules\";
                                ^^
                                ^^

   That compiled?

   You are escaping a double quote there, so where is the
   one that ends the string?


: $_ = "$MckShared";
       ^          ^
       ^          ^  unnecessary and misleading double quotes there

: s/\\/\\\\/g;
: $MckShared = $_;


   You don't need to copy stuff back and forth like that.

   You can replace all three lines above by binding your
   pattern match to the string that you want to test:

       $MckShared =~ s/\\/\\\\/g;



   Why contort yourself in such a manner?

   If you just make the first assignment correctly, then the
   only other statement will be the push().


       $MckShared  = 'c:\perl\modules\\';



: push(@INC, $MckShared);

: Problem is it is not finding the module in the MckShared directory and the
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   What did you do to make it _look_ for a module?

   Nothing in the code that you have shown us...


: script wont compile.  


   You should tell us what messages you got from "wont compile".

   Their _purpose_ is to help figure out what is wrong.

   They help figure out what is wrong.

   You should share them if you want help figuring out what is wrong.



: I cant figure it out.  


    If you cannot clear up syntax errors on your own, then you
    are not yet ready to use modules.

    Learn the fundamentals of Perl first. Then figure out how
    to use modules.


: I look in a Perl Book I have
: and the push looks identical.

: Any help is appreciated.


   Your code above happens at runtime.

   "use SomeModule;" happens at compile time.

   compile time happens _before_ runtime.


   By the time you try to patch up @INC, it is too late.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 14 Apr 1999 22:26:18 -0700
From: Carlos Ramirez <cramirez@gte.net>
To: Andrew Weller <p8e77@keele.ac.uk>
Subject: Re: Reading from file into an array....
Message-Id: <7f3rmu$i6j$1@news-2.news.gte.net>

Try:
$n = 1;
while(<FILE>) {
        ($text,$xval,$yval,$zval,$intensity) = split;
  $data{$n}{text} = $text;
  $data{$n}{x}    = $xval;
  $data{$n}{y}    = $yval;
  $data{$n}{z}    = $zval;
  $data{$n}{intensity} = $intensity;
  $n++;
}

Now you can access your data through this hash.
$data{line_number}{colum_name} = value; where column_name = text,xval,yval,zval
or intensity
This allow you to sort on any of these fields. As opposed to saving them to
seperate arrays, there is no need to know
the index of a specific column value.

## Print your data
foreach $n (sort keys %data) {
        print "Line Number: $n\n";
        foreach ('text','x','y','z','intensity') {
                print "$_ : $data{$n}{$_}\n";
  }
  print "\n";}

Carlos


Andrew Weller wrote:

> Dear All,
>
> I need to write some code in Perl to do the following:
>
> I'm trying to read in a data file which looks like the following:
>
> head       -26.27939        43.58512        14.08601        43.43750
> head       -26.14723        43.68331        14.11775        40.93750
> head       -28.55041        48.04858        15.52853        50.81250
> head       -27.17389        46.06922        14.88883
> 63.93750......etc.....
>
> This data can vary from 1 entry to an infinite amount. I would like to read
> the file in and loop through the set until it reaches the end, reading each
> entry (as: text, xvalues, yvalues, zvalues, intensity). My current code
> looks like this:
>
> -------------------
> #! perl -w                #Win32 platform
>
> #------------------------------
> # Program to read from a file
> # Manipulate the data
> # And save to a new file
> # Author: Andrew Weller
> #------------------------------
>
> {
> get_filename ();
>     open (READFILE, $filename) || die "Can't read $filename: $!";
>     while (<READFILE>) {
>         chomp;
>         my ($text, $xvalues, $yvalues, $zvalues, $intensity) = split;
>         print "$text \t $xvalues \t $yvalues \t $zvalues \t $intensity\n";
> }
>     close (READFILE) || die "Can't close $filename: $!";
> }
>
> # Subroutine that returns a file name to be read to / saved to
> sub get_filename {
>     print "Please enter a directory and file to OPEN / SAVE.\n";
>     print "For example, C:\\MYDOCU~1\\Thesis\\apit1.dat\n\n";
>     chomp ($filename = <STDIN>);
>     return $filename;
> }
>
> -------------------
>
> Although this works fine - what I'm after is, instead of the values being
> printed to screen with the following line:
>
> print "$text \t $xvalues \t $yvalues \t $zvalues \t $intensity\n";
>
> I want the variables to be saved as an array, so that they can be
> manipulated later and saved to a new file.
>
> If there is anybody who could help me, please let me know!
>
> Thanks,
>
> Andy
>
> --
> Andy Weller
> M.Sc. Computing in Earth Sciences
> Dept. of Earth Sciences
> Keele University
> Staffordshire, ST5 5BG, UK
> e-mail: p8e77@keele.ac.uk
> Tel. (+44) 01782 246883



------------------------------

Date: Wed, 14 Apr 1999 23:22:42 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Reading from file into an array....
Message-Id: <MPG.117f25817d998c589898b9@nntp.hpl.hp.com>

In article <7f3rmu$i6j$1@news-2.news.gte.net> on Wed, 14 Apr 1999 
22:26:18 -0700, Carlos Ramirez <cramirez@gte.net> says...

You shouldn't blindly quote the entire article you are responding to.  
And especially you shouldn't quote it after your response.  As someone 
said the other day, Usenet isn't Jeopardy.  Question first, then answer.

> Try:
> $n = 1;
> while(<FILE>) {
>         ($text,$xval,$yval,$zval,$intensity) = split;
>   $data{$n}{text} = $text;
>   $data{$n}{x}    = $xval;
>   $data{$n}{y}    = $yval;
>   $data{$n}{z}    = $zval;
>   $data{$n}{intensity} = $intensity;

One could write the above six lines rather neatly this way:

    @{$data{$n}}{'text', 'x', 'y', 'z', 'intensity'} = split;

>   $n++;
> }

There is absolutely no point in indexing a hash on sequential integers.  
That is what an array is for.  Doing it can lead you into a surprising 
bug, as you will see below.

 ...
> ## Print your data
> foreach $n (sort keys %data) {
>         print "Line Number: $n\n";
>         foreach ('text','x','y','z','intensity') {
>                 print "$_ : $data{$n}{$_}\n";
>   }
>   print "\n";}

The order this will print is 1, 10, 11, ..., 2, 20, ...  Oh, well.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Thu, 15 Apr 1999 02:11:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Sending data to HTML from perl script
Message-Id: <ruv3f7.aj7.ln@magna.metronet.com>

Robert Carter (robert@chackmore.demon.co.uk) wrote:

: print "Content-type: text/html\n\n";
: print"hello world";

: The browser opens a new page automatically and displays the message.


   That is because it is so forgiving even when you lie to it.

   You said you were going to give it HTML, but you 
   gave it plain text.


: 1.    I want to define the background that the browser uses when it displays
: the output from the script. Is there a command for this?


   Yes.

   But it is an HTML thing.

   This is the Perl newsgroup.

   The HTML newsgroup is elsewhere:


      comp.infosystems.www.authoring.html


: 2.    Can I print to the current page?


   Yes.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 15 Apr 1999 05:53:13 GMT
From: leejola@my-dejanews.com
Subject: SQL and the ODBC module
Message-Id: <7f3us7$ojh$1@nnrp1.dejanews.com>

I am using the ODBC module to interface with and Access 97 database for a
web-based project. I need to use an "INSERT INTO" statement to append a new
record to the database. I was using the statement shown below and yet still it
doesn't work. Any assistance given to help solve this problem would be greatly
appreciated.

$db->Sql("INSERT INTO tblPayeeList (Payee, Address, City, PayeeDescr, AcctNum,
Phone) VALUES ('$PayeeName', '$Address', '$City', '$PayeeType', '$AccountNum',
'$Phone') WHERE Username = '$LoginName'");

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Thu, 15 Apr 1999 04:16:59 GMT
From: suribond@my-dejanews.com
Subject: stripping html tags
Message-Id: <7f3p7m$kae$1@nnrp1.dejanews.com>

dear sirs,
         Is there an built in utility in perl(or any other language)
that removes the html tags from a html file and gives only its
text content.

thanking you all

suresh
email suresh.kumar@rocketmail.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: 15 Apr 1999 07:43:23 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: stripping html tags
Message-Id: <7f45ar$gov$2@client2.news.psi.net>

suribond@my-dejanews.com (suribond@my-dejanews.com) wrote on MMLIII
September MCMXCIII in <URL:news:7f3p7m$kae$1@nnrp1.dejanews.com>:
;; dear sirs,
;;          Is there an built in utility in perl(or any other language)
;; that removes the html tags from a html file and gives only its
;; text content.

No, of course not. Perl is totally unaware of the existance of
HTML, PDF, GIF and MIDI. There are rumours that it can handle
beer though.

However, there are modules on CPAN that you can use.


Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


------------------------------

Date: 15 Apr 1999 05:25:32 GMT
From: loans2001@aol.com (Loans2001)
Subject: Trying to get the cgi script to print the date last updated rates!
Message-Id: <19990415012532.24018.00000830@ng14.aol.com>

#<-- Begin Code -->

$mod_time = (stat("../coastal/rates/rates.htm"))[9];

# Last modified time is index 9 of array returned by stat, so we
# grab that only.  We then go on to get the time in a usable
# format by supplying this number (remember it is in epoch
# seconds) to the localtime function, and return only the
# info we are interested in.

($min,$hour,$day,$mon,$yr) = (localtime($mod_time))[1..5];
# We now need to do some modifications, because of the format
# of the numbers returned by localtime, i.e., year is the
# number of years since 1900, month numbers run from 0 to
# 11, and also remember the time is returned in 24 hour
# (military) format.  For printing, we force the hours and
# minutes to print with two numbers for cases like 00:05,
# which would normally print as 0:5.

$yr += 1900;
#if ($mon=12) { 
#	$mon=1;
#}

$outstr = "3/$day/$yr at  ".sprintf("%.2d",$hour).':'.sprintf("%.2d", $min);

# print '/'. $day.'/'.$yr.' at '.sprintf("%.2d",$hour).':'.sprintf("%.2d",
min);
print $outstr;

#<-- End Code -->

This code prints a "1" in front of the date ie 4-18-99  so 14/18/99

Why does it print a silly "1"?

That's the current problem.

My site is located at http://www.mortgage-pros.com  

Clink on the indexes/rates tab.

The script works ok. I would really like to fix this.

Any suggestions?

Thanks.

Scot King
Loans2001@aol.com


------------------------------

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5388
**************************************

home help back first fref pref prev next nref lref last post